# Rationale for Pipe Order of Operations?

**URL:** <https://discourse.julialang.org/t/rationale-for-pipe-order-of-operations/73694>\
**Category:** General Usage\
**Tags:** question, piping\
**Created:** [December 28, 2021, 3:19am UTC](https://discourse.julialang.org/t/rationale-for-pipe-order-of-operations/73694 "2021-12-28T03:19:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kapple](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kapple/32/218915_2.png) [@kapple](https://discourse.julialang.org/u/kapple)\
**Post date:** [December 28, 2021, 3:19am UTC](https://discourse.julialang.org/t/rationale-for-pipe-order-of-operations/73694/1 "2021-12-28T03:19:06Z")

</div>

I feel like both blocks should result in the same result of `7`.

![Pipe1](https://global.discourse-cdn.com/julialang/original/3X/f/0/f0ad25e98031f47fcd4d78c7624f8c9495b3f81d.png)

![Pipe2](https://global.discourse-cdn.com/julialang/original/3X/c/c/cca360f3c8eaf791e823d78083ed115af88ebc4a.png)

Is there a reason why the pipe isn’t the last thing processed?

---

<div class="post-metadata">

**Author:** ![LeePhillips](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leephillips/32/205514_2.png) [@LeePhillips](https://discourse.julialang.org/u/LeePhillips)\
**Post date:** [December 28, 2021, 5:39am UTC](https://discourse.julialang.org/t/rationale-for-pipe-order-of-operations/73694/2 "2021-12-28T05:39:25Z")

</div>

The table of order of operations is in the manual at [Mathematical Operations and Elementary Functions · The Julia Language](https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity).  
Note that |\> comes before the comparison operators. So your second version is equivalent to

```julia
diff(depths) .> (0 |> sum)

```

and `(0 |> sum) == 0`

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [December 28, 2021, 6:22am UTC](https://discourse.julialang.org/t/rationale-for-pipe-order-of-operations/73694/3 "2021-12-28T06:22:20Z")

</div>

Maybe @kapple is asking why is that a good precedence level for `|>`

---

<div class="post-metadata">

**Author:** ![kapple](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kapple/32/218915_2.png) [@kapple](https://discourse.julialang.org/u/kapple)\
**Post date:** [January 1, 2022, 2:52am UTC](https://discourse.julialang.org/t/rationale-for-pipe-order-of-operations/73694/4 "2022-01-01T02:52:55Z")

</div>

Thanks @LeePhillips for the reference.

As @jzr points out, I’m wondering why this order is implemented.

I feel like, I want to do a few things, then pipe the result through.

---

<div class="post-metadata">

**Author:** ![LeePhillips](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leephillips/32/205514_2.png) [@LeePhillips](https://discourse.julialang.org/u/LeePhillips)\
**Post date:** [January 1, 2022, 3:33am UTC](https://discourse.julialang.org/t/rationale-for-pipe-order-of-operations/73694/5 "2022-01-01T03:33:31Z")

</div>

Your preference makes sense to me. I think the pipe should be the most loosely bound operator. But I suspect there’s a reason for it being where it is that hasn’t occurred to me.
