Suppose I have a function like this:
from toolz.curried import *
@curry
def foo(x, y):
print(x, y)
Then I can call:
foo(1,2)
foo(1)(2)
Both are returning as expected.
However, I would like to do something like this:
@curry.inverse
def bar(*args, last):
print(*args, last)
bar(1,2,3)(last)
The idea is that I would like to pre-configure the function and then put it in such a channel:
pipe(data,
f1,
bar(1,2,3)
)
It bar(1,2,3)(data)
will then be called as part of the channel. However, I do not know how to do this. Any ideas? Thank you very much!
Edit:
A more graphic example was requested. So here:
import pandas as pd
from toolz.curried import *
df = pd.DataFrame(data)
def filter_columns(*args, df):
return df[[*args]]
pipe(df,
transformation_1,
transformation_2,
filter_columns("date", "temperature")
)
As you can see, a DataFrame is passed through functions, and filter_columns
one of them is passed . However, the function is preconfigured and returns a function that accepts only a DataFrame similar to a decorator. The same behavior can be achieved with this:
def filter_columns(*args):
def f(df):
return df[[*args]]
return f
, , filter_columns()(df)
, .