This blogpost proposed this implementation of a curried addition function:
def addN(n):
return lambda x: x + n
def plus(a, b):
addA=addN(a)
return addA(b)
I believe my version is more correct because it uses unary functions all the way.
from operator import add
plus = lambda a: lambda b: add(a, b)
plus(1)(2)
What do you think ?
Your
plusfunction is identical to theaddNfunction from the blog post. The only differences are:lambdawhere the blog post used adef.operator.add(a,b)instead of simplya+b.Usage of
plusandaddNwill give the same results so neither one is more “correct”.Note that the function naming you chose is confusing since your
plusfunction corresponds to theaddNfunction (rather than theplusfunction) from the blog post.