UniCoreFW

conjoin()

Returns a function that tests whether **all** elements of a sequence pass **all** of the provided predicates.

Implementation

Args: *preds: Functions to conjoin. Returns: A function that takes an iterable, and returns True if all elements of the iterable pass all predicates, False otherwise.

Example

is_even = lambda x: x % 2 == 0 is_positive = lambda x: x > 0 both = conjoin(is_even, is_positive) both([2, 4, 6])

Expected output: True

Alternative usage:

both([2, 4, 6, -2])

Expected output: False

Source Code

def conjoin(*preds): def wrapper(seq): return all(all(p(x) for p in preds) for x in seq) return wrapper