[issue13430] Add a curry function to the functools module
Marko Nervo
report at bugs.python.org
Fri Nov 18 20:38:15 CET 2011
Marko Nervo <marko at python.it> added the comment:
> But so does functools.partial. So the question is, what use case does it
> help that functools.partial doesn't?
Sure, it's common `defining new functions on other functions`... more times. Here a stupid example with fold (our reduce).
@curry
def fold(function, start, sequence):
if len(sequence) == 0:
return start
else:
return fold(function, function(start, sequence[0]), sequence[1:])
Now, someone could be define a generic summer function by fold.
import operator as op
summer = fold(op.add)
Now, an other programmer could be use summer for defining listsummer (a function which sum only list), as follow.
listsummer = summer([])
In addition, curry is cleaver than functools.partial.
summer = functools.partial(fold, op.add)
listsummer = functools.partial(summer, [])
However, it is an additional feature. Nobody forces you to use it, but if you need it... Yeah, you could rewrite it each time, but why? It is perfect in functools (:
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13430>
_______________________________________
More information about the Python-bugs-list
mailing list