chained¶
-
class
iteration_utilities.
chained
(*funcs, /, reverse=False, all=False)¶ Chained function calls.
- Parameters
- Returns
- chained_funccallable
The chained funcs.
Examples
chained simple calls all funcs on the result of the previous one:
>>> from iteration_utilities import chained >>> double = lambda x: x*2 >>> increment = lambda x: x+1 >>> double_then_increment = chained(double, increment) >>> double_then_increment(10) 21
Or apply them in reversed order:
>>> increment_then_double = chained(double, increment, reverse=True) >>> increment_then_double(10) 22
Or apply all of them on the input:
>>> double_and_increment = chained(double, increment, all=True) >>> double_and_increment(10) (20, 11)
-
__call__
(*args, **kwargs)¶ Depending on the reverse and all argument the function returns:
reverse
all
returns
False
False
func_1(...(func_n(*args, **kwargs)))
True
False
func_n(...(func_1(*args, **kwargs)))
False
True
(func_1(*args, **kwargs), ..., func_n(*args, **kwargs))
True
True
(func_n(*args, **kwargs), ..., func_1(*args, **kwargs))