Skip to content

Commit

Permalink
first commit, with a try
Browse files Browse the repository at this point in the history
  • Loading branch information
zydmayday committed Mar 13, 2022
1 parent cfef6a7 commit 9a36468
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from inspect import signature

def curry(fn):
sig = signature(fn)
return curryN(len(sig.parameters), fn)

def curryN(n, fn):
return _curryN(n, [], fn)

def _curryN(n, saved, fn):
def f1(*rest):
newSaved = saved + list(rest)
newSaved = newSaved[:]
if len(newSaved) >= n:
return fn(*newSaved)
else:
return _curryN(n, newSaved, fn)
return f1

def add(a, b):
return a + b

def multiAdd(a, b, c):
return a + b + c

if __name__ == '__main__':
curryAdd = curry(add)
res = curryAdd(1)(2)
print(res)

curryMultiAdd = curry(multiAdd)
print(curryMultiAdd(1)(2)(3))

0 comments on commit 9a36468

Please sign in to comment.