Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes (Dec 2023) #515

Merged
merged 8 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix itertools.accumulate
  • Loading branch information
inumanag committed Dec 24, 2023
commit e8ec243a73f3fb656ae4446e5b305e8ff65de26b
22 changes: 11 additions & 11 deletions stdlib/itertools.codon
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ def accumulate(iterable: Generator[T], func=lambda a, b: a + b, initial=0, T: ty
total = func(total, element)
yield total

# @inline
# @overload
# def accumulate(iterable: Generator[T], func=lambda a, b: a + b, T: type):
# """
# Make an iterator that returns accumulated sums, or accumulated results
# of other binary functions (specified via the optional func argument).
# """
# total = None
# for element in iterable:
# total = element if total is None else func(unwrap(total), element)
# yield unwrap(total)
@inline
@overload
def accumulate(iterable: Generator[T], func=lambda a, b: a + b, T: type):
"""
Make an iterator that returns accumulated sums, or accumulated results
of other binary functions (specified via the optional func argument).
"""
total: Optional[T] = None
for element in iterable:
total = element if total is None else func(unwrap(total), element)
yield unwrap(total)

@tuple
class chain:
Expand Down
12 changes: 12 additions & 0 deletions test/parser/types.codon
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,18 @@ foo("he", z) #: hewoo
X(s='lolo') #: lolo lolo Int[1]
X('abc') #: abc abc Int[2]


def foo2(x: Static[str]):
print(x, x.__is_static__)
s: Static[str] = "abcdefghijkl"
foo2(s) #: abcdefghijkl True
foo2(s[1]) #: b True
foo2(s[1:5]) #: bcde True
foo2(s[10:50]) #: kl True
foo2(s[1:30:3]) #: behk True
foo2(s[::-1]) #: lkjihgfedcba True


#%% static_getitem
print Int[staticlen("ee")].__class__.__name__ #: Int[2]

Expand Down