Created
April 3, 2019 02:18
-
-
Save xhluca/4f5b7273ff3f643e3c0c9ca284490bc7 to your computer and use it in GitHub Desktop.
Pseudo-currying 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
from inspect import signature | |
def curry(function): | |
def helper(args, remain_count): | |
if remain_count == 0: | |
return function(*args) | |
def mid_func(arg): | |
return helper(args + [arg], remain_count - 1) | |
return mid_func | |
sig = signature(function) | |
return helper([], len(sig.parameters)) | |
def func(a, b, c, d, e, f): | |
return a + b + c + d + e + f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment