Nested Pipes

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

What package are you using?

1 Like

Pipe.jl

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

1 Like

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.

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.

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

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]
2 Likes

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