Last active
June 20, 2016 20:29
-
-
Save Nazek42/014b4d38b77f7b27100b39279e1d602d to your computer and use it in GitHub Desktop.
Python Currying
This file contains 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
import functools | |
import inspect | |
# Decorator | |
def curry(func): | |
sig = inspect.signature(inspectable(func)) | |
@functools.wraps(func) | |
def wrapper(*args, **kwargs): | |
try: | |
sig.bind(*args, **kwargs) | |
return func(*args, **kwargs) | |
except TypeError: | |
return functools.partial(func, *args, **kwargs) | |
return wrapper | |
def inspectable(func): | |
def wrapper(*args, **kwargs): | |
return func(*args, **kwargs) | |
return wrapper |
Author
Nazek42
commented
Jun 20, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment