|> followed by .|> Gives an error
@pipe 2 |> _ .+ (1:3) #Works
@pipe 2 .+ (1:3) .|> _^2 #Works
@pipe 2 |> _ .+ (1:3) .|> _^2 #Gives Error
Is there a way around this?
It works the other way round: .|> followed by |>
Example
@pipe (1:3) .|> _^2 |> sum #Works
2 Likes
xiaodai
September 24, 2020, 5:22am
2
using MacroTools
MacroTools.prettify(@macroexpand @pipe 2 |> _ .+ (1:3) .|> _^2 )
gives
:((2 |> 2 .+ (1:3)) .|> (mosquito->mosquito ^ 2))
but this works
@pipe 2 |> _ .+ (1:3) |> _ .^ 2
I think it’s just a parseing bug in Pipe.jl, so should raise an issue on github.
2 Likes
this is still giving an error. I haven’t raised an issue before. can you send a link to the place
This thread is from 4.5 years ago, the landscape was quite different back then
With DataPipes.jl , one can write the original example from the first post basically without any changes, and continue using .|>
:
julia> @p 2 |> __ .+ (1:3) .|> __^2
3-element Vector{Int64}:
9
16
25
or use `map` as you suggest
julia> @p 2 |> __ .+ (1:3) |> map(_^2)
3-element Vector{Int64}:
9
16
25
1 Like
Nice!
And how do I do this?
julia> Pipe.@pipe """[{"a":1},{"a":2},{"a":3}]""" |> JSON.parse .|> _["a"]
3-element Vector{Int64}:
1
2
3
julia> DataPipes.@pipe """[{"a":1},{"a":2},{"a":3}]""" |> JSON.parse .|> _["a"]
ERROR: syntax: all-underscore identifier used as rvalue around /home/hugo/.julia/packages/DataPipes/emgTy/src/pipe.jl:211
That’s
@p """[{"a":1},{"a":2},{"a":3}]""" |> JSON.parse .|> __["a"]
In DataPipes.jl, _
refers to the anonymous function argument, like @p 1:3 |> map(_ + 1)
. Use __
to refer to the previous step of the pipeline.
1 Like