This function f accepts an argument list and returns another callable with the same argument list, so that other functions can be applied to it.
from operator import add, mul
def f(*a, **kw):
return lambda g: g(*a, **kw)
map(f(3, 10), (add, mul)) # -> [13, 30]
What do you call f
? Is this a combinator of some kind?
The combinator is a curried form of apply. Compared to the (deprecated) built-in function apply
, f
reverses the order of the arguments to be more useful, providing what looks like a dual to the functools.partial function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With