Created
August 9, 2016 13:46
-
-
Save justinfay/9e929c83079f2a0a462edf8062d84f5e to your computer and use it in GitHub Desktop.
Simply curried functions in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def curry(func, args=None): | |
args = args if args else [] | |
def curried(arg): | |
args.append(arg) | |
try: | |
return func(*args) | |
except TypeError: | |
return curry(func, args) | |
curried.__name__ = "curry(%s)" % func.__name__ | |
return curried |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment