Pipe 适用于单个参数 fn,但如何将其用于具有多个参数的 fn?
这个版本可以用,但是真的很难看
two_args_fn(a, b) = a + b
1 |> (tmp) -> two_args_fn(tmp, 2) |> println # => 3
有更好的选择吗,比如
1 |> two_args_fn(2) |> println # => 3
或
1 |> two_args_fn(_, 2) |> println # => 3
一种方法是添加包 Pipe.jl,显式导入其宏
@pipe
,然后在管道表达式前面加上 @pipe
。
import Pipe: @pipe
@pipe 1 |> two_args_fn(_, 2) |> println
# 3