Skip to content

Commit

Permalink
Support any and all
Browse files Browse the repository at this point in the history
  • Loading branch information
zhukovgreen committed Nov 29, 2024
1 parent 5462e79 commit 045ab59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions friendly_sequences/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ def join(
) -> str:
return with_.join(self)

def all(
self: Seq[T],
) -> bool:
return all(self)

def any(
self: Seq[T],
) -> bool:
return any(self)

def __iter__( # noqa: PYI034
self: Seq[T],
) -> Iterator[T]:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_friendly_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def add_one(i: int) -> int:
.reduce(lambda left, right: left + right)
) == "1234"

assert Seq((1, 2, 3)).map(lambda x: x // 2 == 0).all() is False
assert Seq((2, 4, 6)).map(lambda x: x // 2 == 0).all() is False
assert Seq((1, 2, 3)).map(lambda x: x // 2 == 0).any() is True


def test_chaining():
def filter_expr(i: int) -> TypeGuard[int]:
Expand Down

0 comments on commit 045ab59

Please sign in to comment.