Marko Nervo <[email protected]> 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 <[email protected]>
<http://bugs.python.org/issue13430>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com