Skip to content

Commit

Permalink
perf: try generators for map and filter (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff authored Feb 12, 2024
2 parents e63b4da + cf2adc6 commit 196a258
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions iterpy/iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def to_set(self) -> set[T]:
def map( # Ignore that it's shadowing a python built-in
self, func: Callable[[T], S]
) -> "Iter[S]":
return Iter([func(i) for i in self._iterator])
return Iter(map(func, self._iterator))

def pmap(
self,
Expand All @@ -107,7 +107,7 @@ def pmap(
return Iter(pool.map(func, self._iterator))

def filter(self, func: Predicate) -> "Iter[T]":
return Iter([i for i in self._iterator if func(i)])
return Iter(filter(func, self._iterator))

def groupby(self, func: Hasher) -> "Iter[tuple[str, list[T]]]":
groups_with_values: defaultdict[str, list[T]] = defaultdict(
Expand Down

0 comments on commit 196a258

Please sign in to comment.