This library does not comply with the Python philosophy TIOOTDI. Leave before you faint.
The word churry is the combination of chain and curry, which implies that the library named as such does the same.
Affirmative to that. This library enables you to make a function chainable and curriable.
Suppose we have a function:
def move(ball, from_=0, to=10):
pass
Normally, we would
move(spam, 1, 5)
# or
move(spam, from_=1, to=5)
Now, with the churry decorator
from churry import churried
@churried()
def move(ball, from_=0, to=10):
pass
we can
move.from_(1).to(5)(spam)
Note that for functions with variable arguments (both positional or keyword), churry wouldn't know when to stop receiving arguments. So you have to call the churried function with empty argument to inform churry that it's time to evaluate. For example,
@churried()
def move_simultaneously(*balls, from_=0, to=10)
pass
move_simultaneously(foo, bar).from_(1).to(5)()
# or
move_simultaneously.from_(1).to(5)(foo, bar)()
With immutable churry, you can
move_to_1_5 = move_simultaneously.from_(1).to(5)
move_to_1_5(foo, bar)()
move_to_1_5(bar, foo)()
move_to_1_5(spam, ham)()
I may have wrongly used the terms chain and curry, but that's not important (at least to me). What's important now is that you can churry a function.
If the function you want to decorate does not have variable positional or variable keyword argument, you must supply the keyword arguments before the positional arguments are supplied. Because when positional arguments are fully supplied, churry evaluates the function with the default argument values.
In short, do
move.from_(1).to(5)(spam)
# or
move.to(5).from_(1)(spam)
Do not
move(spam).from_(1).to(5)
# this raises AttributeError because NoneType (return value of move(spam))
# does not have attribute 'from_'
If you do not want this feature (or whatever it is), use the explicit
switch
so that churry only does evaluation after you call it with empty argument.
See tests.py
.
Please check out the other branch of this project mutable-churry
, pay
attention to section curriability
.
This library is licensed under GPLv3.