Skip to content

Commit 6a3b07f

Browse files
author
czheo
committed
make * support infinity
1 parent e672f42 commit 6a3b07f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

syntax_sugar/iter.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .pipe import pipe
2-
from itertools import product, islice
2+
from itertools import tee, islice
33

44
INF = float('inf')
55
NEGINF = float('-inf')
@@ -18,15 +18,18 @@ def __iter__(self):
1818
return self
1919

2020
def __mul__(self, rhs):
21-
self.data = product(self, rhs)
22-
return self
21+
def product(rhs):
22+
for e1 in self:
23+
rhs, rhs_copy = tee(rhs)
24+
for e2 in rhs_copy:
25+
yield (e1, e2)
26+
return Iterator(product(rhs))
2327

2428
def __next__(self):
2529
return next(self.data)
2630

2731
def slice(self, start=0, stop=None, step=1):
28-
self.data = islice(self.data, start, stop, step)
29-
return self
32+
return Iterator(islice(self.data, start, stop, step))
3033

3134
class Range:
3235
def __init__(self, start, end):

0 commit comments

Comments
 (0)