Skip to content

Commit

Permalink
misc.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff committed Nov 22, 2023
1 parent 600019f commit 46b6f73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions functionalpy/_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def reduce(self, func: Callable[[_T0, _T0], _T0]) -> _T0:

def groupby(
self, func: Callable[[_T0], str]
) -> dict[str, tuple[_T0, ...]]:
) -> "Seq[Group[tuple[_T0, ...]]]":
# Itertools.groupby requires the input to be sorted
sorted_input = sorted(self._seq, key=func)

result = {
Expand All @@ -60,7 +61,12 @@ def groupby(
)
}

return result
groups = (
Group(key=key, value=value)
for key, value in result.items()
)

return Seq(groups)

def flatten(self) -> "Seq[_T0]":
return Seq(
Expand Down
2 changes: 1 addition & 1 deletion functionalpy/_sequence.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Seq(Generic[_T0]):
def reduce(self, func: Callable[[_T0, _T0], _T0]) -> _T0: ...
def groupby(
self, func: Callable[[_T0], str]
) -> dict[str, tuple[_T0, ...]]: ...
) -> Seq[Group[tuple[_T0, ...]]]: ...
@overload
def flatten(self: Seq[list[_S]]) -> Seq[_S]: ...
@overload
Expand Down
2 changes: 1 addition & 1 deletion functionalpy/benchmark/query_1/iterators_q1.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def main_iterator(data: Sequence[Item]) -> Sequence[CategorySummary]:
sequence = (
Seq(data)
.filter(lambda i: i.ship_date <= dt.datetime(2000, 1, 1))
.group_by(
.groupby(
lambda i: f"status_{i.cancelled}_returned_{i.returned}"
)
.map(summarise_category)
Expand Down

0 comments on commit 46b6f73

Please sign in to comment.