Skip to content

Commit

Permalink
fix: Iter[iter].flatten() should return Iter (#94)
Browse files Browse the repository at this point in the history
fix: Iter[iter].flatten() should return Iter

update _iter.py and test_iter.py
  • Loading branch information
MartinBernstorff authored Jan 23, 2024
2 parents c2ea2d3 + e7f776c commit c8790a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions iterpy/_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def flatten(self) -> "Iter[T]":
for i in self._iterator:
if isinstance(i, Sequence) and not isinstance(i, str):
values.extend(i)
elif isinstance(i, Iter):
values.extend(i.to_list())
else:
values.append(i)

Expand Down
3 changes: 2 additions & 1 deletion iterpy/test_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def test_flatten_iterator(self):
def test_flatten_iter_iter(self):
iterator: Iter[int] = Iter([1, 2])
nested_iter: Iter[Iter[int]] = Iter([iterator])
unnested_iter: Iter[int] = nested_iter.flatten() # noqa: F841, RUF100
unnested_iter: Iter[int] = nested_iter.flatten()
assert unnested_iter.to_list() == [1, 2]

def test_flatten_str(self):
test_input: list[str] = ["abcd"]
Expand Down

0 comments on commit c8790a7

Please sign in to comment.