Python currying with any number of variables
I am trying to use currying to make a simple functional add in Python. I found this curry decorator here. def curry(func): def curried(*args, **kwargs): if len(args) + len(kwargs) >= func.__code__.co_argcount: return func(*args, **kwargs) return (lambda *args2, **kwargs2: curried(*(args + args2), **dict(kwargs, **kwargs2))) return curried @curry def foo(a, b, c): return a + b + c Now this is great because I can do some simple currying: >>> foo(1)(2, 3) 6 >>> foo(1)(2)(3) 6 But this only works for exactly three variables. How do I write the function foo so that it can accept any number of varia
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.