Method chaining with arguments to imitate unix piping?


#1

dear julia experts: I am trying to understand method chaining. I believe that instead of f(g(x)), this means I can use g(x) |> f().

Can one do more than this? Say, I have defined

julia> grep(heystack,needle) = filter( x->contains(x, needle), heystack )
grep (generic function with 1 method)

is it possible to accomplish something like readdir("/etc") |> grep("password"), akin to Unix piping, in Julia now? I suspect not, but was wondering…

regards, /iaw


#2

Nope, this means that you can use g(x) |> f, ie you use f as a function.

You can of course do that, but you have to make the second argument of |> a closure, eg s -> ismatch(regex, s).


#3

See https://github.com/MikeInnes/Lazy.jl/blob/master/README.md#macros
for chaining with arguments