Pipes and broadcasts

broadcast

#1

The following does not work, is this a bug?

(3, 3) |> abs.

this one does work of course

(3, 3) |> x -> abs.(x)

but is a bit verbose.


#2

No bugs here

(3, 3) .|> abs does work and abs.((3, 3)) is easier to read and shorter.


#3

What you are trying to do doesn’t work because abs. does not exists. The . notation is a syntax sugar that gets translated to a broadcast call. You can inspect this.

julia> expand(:(abs.(x)))
:((Base.broadcast)(abs, x))

#4

thanks, of course this is only a toy example, my applied case is a bit longer.


#5

x |> fn. |> fn2. |> fn3. |> fn4.
etc etc is better than

fn4.(fn3.(fn2.(fn.(x))))

I think |> should work with broadcasts