Does this combinator have a name?

This function f takes a list of arguments and returns another called with the same list of arguments, 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 some kind of combinator?

+6
source share
2 answers

The combinator is a curried form of apply . Compared to the (deprecated) built-in apply function, f overrides the argument order to be more useful by providing what looks like a double to functools.partial .

+4
source

It is pretty closely related to partial , but not the same.

partial takes a function and some arguments and returns the called call, which calls the given call with combined parameters.

 def pr(x): print (x) # making it fit for 2.x and 3.x p = functools.partial(pr, 1, 2, 3) p() # prints 1, 2, 3 q = f(1, 2, 3) p(pr) # prints 1, 2, 3 
0
source

Source: https://habr.com/ru/post/901037/


All Articles