UniCoreFW

anyof()

Returns a function that takes a single argument and returns True if any of the given functions, when called with that argument, return True.

Implementation

Parameters: *funcs: Callable[[Any], bool] Zero or more predicate functions to test. Returns: Callable[[Any], bool] A function that takes an argument and returns True if any of the given predicates return True, False otherwise.

Example

def is_even(x): return x % 2 == 0 def is_positive(x): return x > 0 is_even_or_positive = anyof(is_even, is_positive) is_even_or_positive(2) # True is_even_or_positive(-3) # False

Expected output:

Source Code

def anyof(*funcs: Callable[[Any], bool]) -> Callable[[Any], bool]: def wrapper(arg: Any) -> bool: return any(f(arg) for f in funcs) wrapper.__name__ = "anyof" wrapper._argcount = 1 # type: ignore return wrapper