Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does this combinator have a name?

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?

like image 974
James Faulcon Avatar asked Nov 08 '11 15:11

James Faulcon


1 Answers

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.

like image 108
Michael J. Barber Avatar answered Oct 02 '22 14:10

Michael J. Barber