Skip to content

Commit 357264d

Browse files
authored
Merge pull request #9 from ourstudio-se/8-filter_map_concat-needs-to-copy-input-if-iterator
8 filter map concat needs to copy input if iterator
2 parents 55dbafd + 79e6230 commit 357264d

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

maz/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ def __init__(
319319
self.fmap_function = fmap_function
320320

321321
def __call__(self, objects: typing.Iterable[typing.Any]) -> typing.Iterable[typing.Any]:
322+
objects_t, objects_f = itertools.tee(objects)
322323
return map(
323324
operator.itemgetter(1),
324325
sorted(
@@ -330,7 +331,7 @@ def __call__(self, objects: typing.Iterable[typing.Any]) -> typing.Iterable[typi
330331
self.filter_predicate,
331332
operator.itemgetter(1),
332333
),
333-
enumerate(objects)
334+
enumerate(objects_t)
334335
),
335336
),
336337

@@ -342,7 +343,7 @@ def __call__(self, objects: typing.Iterable[typing.Any]) -> typing.Iterable[typi
342343
self.filter_predicate,
343344
operator.itemgetter(1),
344345
),
345-
enumerate(objects)
346+
enumerate(objects_f)
346347
),
347348
)
348349
),

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = maz
3-
version = 0.0.4
3+
version = 0.0.5
44
author = ourstudio
55
author_email = rikard@ourstudio.se
66
description = Functional programming tools.

tests/test_maz.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ def __init__(self, id: str, n: int):
105105
def __eq__(self, o):
106106
return (self.id == o.id) and (self.n == o.n)
107107

108-
items = [
108+
items = iter([
109109
Var("a", 1),
110110
Var("b", 2),
111111
Var("c", 3),
112112
Var("d", 4),
113113
Var("e", 5),
114-
]
114+
])
115115

116116
fmc_fn = maz.filter_map_concat(
117117
lambda x: x.n > 2,

0 commit comments

Comments
 (0)