Skip to content

Instantly share code, notes, and snippets.

@xhluca
Created April 3, 2019 02:18
Show Gist options
  • Save xhluca/4f5b7273ff3f643e3c0c9ca284490bc7 to your computer and use it in GitHub Desktop.
Save xhluca/4f5b7273ff3f643e3c0c9ca284490bc7 to your computer and use it in GitHub Desktop.
Pseudo-currying in Python
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