# chaining and (dot) operations

**URL:** <https://discourse.julialang.org/t/chaining-and-dot-operations/18648>\
**Category:** New to Julia\
**Created:** [December 14, 2018, 5:38am UTC](https://discourse.julialang.org/t/chaining-and-dot-operations/18648 "2018-12-14T05:38:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjspotter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rjspotter/32/6433_2.png) [@rjspotter](https://discourse.julialang.org/u/rjspotter)\
**Post date:** [December 14, 2018, 5:38am UTC](https://discourse.julialang.org/t/chaining-and-dot-operations/18648/1 "2018-12-14T05:38:59Z")

</div>

First I admit I have some Elixir experience that leads me to have intuition about |\> that is wrong. That said…

I was reading the docs and playing with some data and realized I could use .|\> rather like a call to map

> julia\> [1:5;] .|\> x → x^2  
> 5-element Array{Int64,1}:  
> 1  
> 4  
> 9  
> 16  
> 25

but, I can’t seem to switch back to the |\> behaviour I expect

> julia\> [1:5;] .|\> x → x^2 |\> sum  
> 5-element Array{Int64,1}:  
> 1  
> 4  
> 9  
> 16  
> 25

I expect 55 not an Array

Can someone explain why my intuition is wrong and what I’m missing, Thanks.

---

<div class="post-metadata">

**Author:** ![afternone](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@afternone](https://discourse.julialang.org/u/afternone)\
**Post date:** [December 14, 2018, 7:40am UTC](https://discourse.julialang.org/t/chaining-and-dot-operations/18648/2 "2018-12-14T07:40:39Z")

</div>

```julia
julia> ([1:5;] .|> x->x^2) |> sum
55

```

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [December 14, 2018, 7:45am UTC](https://discourse.julialang.org/t/chaining-and-dot-operations/18648/3 "2018-12-14T07:45:08Z")

</div>

This works too

```
[1:5;] .|> (x -> x^2) |> sum

```

---

<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:** [December 14, 2018, 7:49am UTC](https://discourse.julialang.org/t/chaining-and-dot-operations/18648/4 "2018-12-14T07:49:28Z")

</div>

To add to the above explanations: your original expression is parsed as

```julia
[1:5;] .|> x-> (x^2 |> sum)

```

You can see this by comparing the output of

```julia
julia> Meta.show_sexpr(:([1:5;] .|> x->x^2 |> sum))
(:call, :.|>, (:vcat, (:call, :(:), 1, 5)), (:->, :x, (:block,
      :(#= REPL[16]:1 =#),
      (:call, :|>, (:call, :^, :x, 2), :sum)
    )))
julia> Meta.show_sexpr(:([1:5;] .|> x-> (x^2 |> sum)))
(:call, :.|>, (:vcat, (:call, :(:), 1, 5)), (:->, :x, (:block,
      :(#= REPL[17]:1 =#),
      (:call, :|>, (:call, :^, :x, 2), :sum)
    )))

```
