Skip to content

Instantly share code, notes, and snippets.

@rossdylan
Created February 2, 2013 17:00
Show Gist options
  • Save rossdylan/4698298 to your computer and use it in GitHub Desktop.
Save rossdylan/4698298 to your computer and use it in GitHub Desktop.
implicit function currying in python
"""
Decorator which takes a int which is the maximum number of args the decorated function can take
"""
class curryable(object):
def __init__(self, numArgs):
self.numArgs = numArgs
def __call__(self, func):
if self.numArgs > 0:
@curryable(self.numArgs-1)
def wrapper(*args, **kwargs):
if len(args) < self.numArgs:
return partial(func, *args)
else:
return partial(func, *args)(**kwargs)
return wrapper
else:
return func
@curryable(5)
def test_func(one,two,three,four,five):
print(one)
print(two)
print(three)
print(four)
print(five)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment