# Method chaining with arguments to imitate unix piping?

**URL:** <https://discourse.julialang.org/t/method-chaining-with-arguments-to-imitate-unix-piping/9308>\
**Category:** General Usage\
**Created:** [February 25, 2018, 5:15am UTC](https://discourse.julialang.org/t/method-chaining-with-arguments-to-imitate-unix-piping/9308 "2018-02-25T05:15:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [February 25, 2018, 5:15am UTC](https://discourse.julialang.org/t/method-chaining-with-arguments-to-imitate-unix-piping/9308/1 "2018-02-25T05:15:09Z")

</div>

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
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

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 25, 2018, 6:43am UTC](https://discourse.julialang.org/t/method-chaining-with-arguments-to-imitate-unix-piping/9308/2 "2018-02-25T06:43:43Z")

</div>

> [@iwelch](#):
>
> I believe that instead of `f(g(x))`, this means I can use `g(x) |> f()`

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

> [@iwelch](#):
>
> accomplish something […] akin to Unix piping

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

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [February 25, 2018, 7:20am UTC](https://discourse.julialang.org/t/method-chaining-with-arguments-to-imitate-unix-piping/9308/3 "2018-02-25T07:20:59Z")

</div>

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