Coverage for src/remedapy/all_pass.py: 100%

1 from collections.abc import Callable, Iterable

2 from typing import TypeVar, cast, overload

3

4 T = TypeVar('T')

5

6

7@overload

8 def all_pass(data: T, fns: Iterable[Callable[[T], bool]], /) -> bool: ...

9

10

11@overload

12 def all_pass(fns: Iterable[Callable[[T], bool]], /) -> Callable[[T], bool]: ...

13

14

15 def all_pass(

16 data: T | Iterable[Callable[[T], bool]],

17 fns: Iterable[Callable[[T], bool]] | None = None,

18 /,

19) -> bool | Callable[[T], bool]:

20 if fns is None:

21 data = cast(Iterable[Callable[[T], bool]], data)

22 return lambda value: all_pass(value, data)

23 data = cast(T, data)

24 for fn in fns:

25 if not fn(data):

26 return False

27 return True