aspis.common.all_pass

aspis.common.all_pass(preds, var)[source]

Checks if all predicates in the given sequence return 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 all predicates return True for the given value or iterable; otherwise, False.

Return type:

bool

Examples

With single values:

>>> is_positive = lambda x: x > 0
>>> is_even = lambda x: x % 2 == 0
>>> all_pass([is_positive, is_even], 4)
True
>>> all_pass([is_positive, is_even], -2)
False

With iterables:

>>> all_pass([lambda x: x > 0, lambda x: x < 10], [1, 2, 3])
True
>>> all_pass([lambda x: x > 0, lambda x: x < 10], [1, -2, 3])
False