UniCoreFW

allany()

Returns a function that checks if any of the given predicates return True for every item in the given list.

Implementation

Parameters: *preds: Callable[[Any], bool] Zero or more predicate functions to test. Returns: Callable[[List[Any]], bool] A function that takes a list and returns True if every item in the list satisfies at least one of the given predicates, False otherwise.

Example

def is_even(x): return x % 2 == 0 def is_positive(x): return x > 0 is_even_and_positive = allany(is_even, is_positive) is_even_and_positive([2, 4, 6]) # True is_even_and_positive([1, 3, 5]) # False

Expected output:

Source Code

def allany(*preds: Callable[[Any], bool]) -> Callable[[List[Any]], bool]: def tester(arr: List[Any]) -> bool: for x in arr: if not any(p(x) for p in preds): return False return True tester.__name__ = "allany" tester.__doc__ = allany.__doc__ return tester