# Nested Pipes

**URL:** <https://discourse.julialang.org/t/nested-pipes/49573>\
**Category:** General Usage\
**Tags:** package\
**Created:** [November 4, 2020, 10:15am UTC](https://discourse.julialang.org/t/nested-pipes/49573 "2020-11-04T10:15:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [November 4, 2020, 10:15am UTC](https://discourse.julialang.org/t/nested-pipes/49573/1 "2020-11-04T10:15:24Z")

</div>

For a Pipe within a Pipe is there an \_ equivalent for the inner pipe ?  
\_\_ ? \_2 ?

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [November 4, 2020, 12:49pm UTC](https://discourse.julialang.org/t/nested-pipes/49573/2 "2020-11-04T12:49:40Z")

</div>

What package are you using?

---

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [November 4, 2020, 1:55pm UTC](https://discourse.julialang.org/t/nested-pipes/49573/3 "2020-11-04T13:55:12Z")

</div>

Pipe.jl

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [November 4, 2020, 5:41pm UTC](https://discourse.julialang.org/t/nested-pipes/49573/4 "2020-11-04T17:41:06Z")

</div>

There is not.  
There is no notion of nested pipes in Pipe.jl.  
And as the author of Pipe.jl I can say that it is **not** a features we would be willing to add.  
It is indeed a cool idea.  
But Pipe.jl is basically about being the simplest most straight forward piping mechanism.

There are several more fancy piping packages that might do it though,  
or that might be willing to add it as a feature.  
Here is a list of packages  
[https://github.com/JuliaLang/julia/issues/5571#issuecomment-205754539](https://github.com/JuliaLang/julia/issues/5571#issuecomment-205754539)  
(NB, not related to this topic, but just because I am posting this link and it should have this warning: to _anoyone_ please be very cautious about posting in that thread, it will notify over 100 people; and unless you have read all of its hundreds of comments odds are you will be repreating something)

---

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [November 5, 2020, 5:06am UTC](https://discourse.julialang.org/t/nested-pipes/49573/5 "2020-11-05T05:06:03Z")

</div>

Thanks Lyndon.  
I couldn’t see any examples of packages in the list doing this. Underscores.jl is probably closest.

For background. I like Pipes because I prefer to read logic left-to-right and not have nested brackets.  
I also use them to add many columns to a DataFrame. Nested example below.

```julia
using DataFrames, Pipe, DotMaps, NamedTupleTools

df = DataFrame(a = rand(10))

@pipe eachrow(df) .|> begin  
    r = DotMap(convert(Dict,NamedTuple(_)))    

    r.New = r.a * 2
    r.New2 = r.New + 10
    # ...

    r.New20 = @pipe r.a |> sqrt |> log(__,2) #nested pipe using__
    
    r
end |> DataFrame

```

btw. I’ve used this example in other questions and its not very popular though I still like it.

> [@Piping DataFrame rows](https://discourse.julialang.org/t/piping-dataframe-rows/49576/6):
>
> I was thinking the same thing too.

> [@Is there a better way to do this? many calculated columns](https://discourse.julialang.org/t/is-there-a-better-way-to-do-this-many-calculated-columns/47111/5):
>
> You can also construct DataFrames with NamedTuples: DataFrame( (col\_1 = i, col\_2 = i^2, col\_3 = i^2 + 10) for i in 1:100 ) For more complex operations you could define functions beforehand. func1(x) = x^2 func2(x) = func1(x) + 10 DataFrame( (col\_1 = i, col\_2 = func1(i), col\_3 =func2(i)) for i in 1:100 )

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [November 5, 2020, 9:36am UTC](https://discourse.julialang.org/t/nested-pipes/49573/6 "2020-11-05T09:36:12Z")

</div>

This might be just a 1-line change, to get the macro expand any other macros inside its input before proceeding:

```julia
julia> macro pipe2(ee)
           esc(Pipe.funnel(macroexpand( __module__ , ee)))
       end
@pipe (macro with 1 method)

julia> @pipe2 eachrow(rand(Int8, 3,3)) .|> begin 
          r = map(sqrt∘abs, _)
          @pipe2 r |> _.^2
       end
3-element Vector{Vector{Float64}}:
 [95.99999999999999, 2.0000000000000004, 91.99999999999999]
 [72.99999999999999, 47.99999999999999, 58.99999999999999]
 [40.00000000000001, 50.00000000000001, 4.0]

```

---

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [November 30, 2020, 6:12am UTC](https://discourse.julialang.org/t/nested-pipes/49573/7 "2020-11-30T06:12:55Z")

</div>

This works really well thank you.  
Add it to base if you can.
