To use this place
@pipe at the start of the line for which you want "advanced piping functionality" to work.
This works the same as Julia Piping, except if you place a underscore in the right hand of the expressing, it will be replaced with the lefthand side.
@pipe a |> b(x,_) # == b(x,a) #Not: (b(x,_))(a)
Futher the _ can be unpacked, called, deindexed offetc.
@pipe a |> b(_...) # == b(a...) @pipe a |> b(_(1,2)) # == b(a(1,2)) @pipe a |> b(_) # == b(a)
This last can be used for interacting with multiple returned values. In general however, this is frowned upon. Generally a pipeline is good for expressing a logical flow data through Single Input Single Output functions. When you deindex multiple times, that is case of working with Multiple Input Multiple Output functions. In that case it is likely more clear to create named variables, and call the functions normally in sequence. There is also a performace cost for doing multiple deindexes (see below).
function get_angle(rise,run) atan(rise/run) end @pipe (2,4) |> get_angle(_,_) # == 0.4636476090008061 get_angle(2,4) # == 0.4636476090008061 #Note the ordinary way is much clearer
However, for each
_ right hand side of the
|>, the left hand side will be called.
This can incurr a performance cost.
function ratio(value, lr, rr) println("slitting on ratio $lr:$rr") value*lr/(lr+rr), value*rr/(lr+rr) end function percent(left, right) left/right*100 end @pipe 10 |> ratio(_,4,1) |> percent(_,_) # = 400.0, outputs splitting on ratio 4:1 Twice @pipe 10 |> ratio(_,4,1) |> percent(_...) # = 400.0, outputs splitting on ratio 4:1 Once
about 1 month ago