|
|
|
|
|
by itishappy
305 days ago
|
|
The pipe operator uses what comes before as the first argument of the function. This means in R it would be: result <- df
|> fun1(arg1=1)
|> fun2(arg2=2)
Python doesn't have a pipe operator, but if it did it would have similar syntax: result = df
|> fun1(arg1=1)
|> fun2(arg2=2)
In existing Python, this might look something like: result = pipe(df, [
(fun1, 1),
(fun2, 2)
])
(Implementing `pipe` would be fun, but I'll leave it as an exercise for the reader.)Edit: Realized my last example won't work with named arguments like you've given. You'd need a function for that, which start looking awful similar to what you've written: result = pipe(df, [
step(fun1, arg1=1),
step(fun2, arg2=2)
])
|
|
I like exercise:
https://gist.github.com/stuarteberg/6bcbe3feb7fba4dc2574a989...