Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions iterpy/arr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def __len__(self) -> int:
return len(self._iter)

def __bool__(self) -> bool:
if self.len() == 0:
return False
return self.lazy().__bool__()

def __iter__(self) -> Arr[T]:
Expand Down
9 changes: 9 additions & 0 deletions iterpy/test_arr.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ def test_chain():
assert result == [1, 2, 3, 4]


def test_empty_is_falsy():
test_iterator = Arr([]) # type: ignore
assert not test_iterator

test_iterator = Arr([1])
assert test_iterator
assert bool(test_iterator) is True


@pytest.mark.benchmark()
def test_benchmark_large_flattening():
test_input = Arr(range(100_000)).map(lambda x: Arr([x]))
Expand Down