complement

class iteration_utilities.complement(func)

Invert a predicate function. There is a homonymous function in the toolz package ([0]) but significantly modified.

Parameters:
funccallable

The function to complement.

Returns:
complemented_funccallable

The complement to func.

References

Examples

complement is equivalent to lambda x: not x() but significantly faster:

>>> from iteration_utilities import complement
>>> from iteration_utilities import is_None
>>> is_not_None = complement(is_None)
>>> list(filter(is_not_None, [1,2,None,3,4,None]))
[1, 2, 3, 4]

Note

The example code could also be done with itertools.filterfalse() or iteration_utilities.is_not_None().

__call__(*args, **kwargs)

Returns not func(*args, **kwargs) using func.

func

(callable) The function that is complemented (readonly).

New in version 0.6.