aspis.common.any_pass
- aspis.common.any_pass(preds, var)[source]
Checks if any predicate in the given sequence returns True when applied to the input variable.
- Parameters:
preds (Sequence[Callable[[T], bool]]) – A sequence of predicate functions that take an element of type T and return a boolean.
var (T | Iterable[T]) – The value or iterable of values to test against the predicates.
- Returns:
True if any predicate returns True for the given value or iterable; otherwise, False.
- Return type:
Examples
With single values:
>>> is_positive = lambda x: x > 0 >>> is_even = lambda x: x % 2 == 0 >>> any_pass([is_positive, is_even], 4) True >>> any_pass([is_positive, is_even], -2) True
With iterables:
>>> any_pass([lambda x: x > 5, lambda x: x < 0], [1, 2, 3]) False >>> any_pass([lambda x: x > 5, lambda x: x < 0], [1, -2, 3]) True