Skip to content

markuswt/curry-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

curry-py

Simple currying for python functions.

>>> foo = lambda a, b, m: (a+b) * m
>>> curry(foo)(2)()(3)(10)
50
>>> curry(foo)(2)(3, 10)
50
>>> curry(foo)(2, m=10)(3)
50
>>> curry(foo, 2, 3, 10)()
50
>>> curry(print, "baz")(42)
baz 42
>>> curry(lambda: print(42))()
42

Curry tries to evaluate the function with as few arguments as possible, so try to apply *args and **kwargs together with required arguments.

Curry also works as a decorator.

>>> @curry
... def bar(a, b, m):
...     return (a+b) * m
>>> bar(2)()(3)(10)
50
>>> bar(2)(3, 10)
50
>>> bar(2, m=10)(3)
50
>>> bar(2, 3, 10)
50