# A confusing problem of pipe

**URL:** https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438
**Category:** General Usage
**Tags:** piping
**Created:** [May 19, 2021, 1:07pm UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438 "2021-05-19T13:07:35Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/314/32/25228_2.png) [@314](https://discourse.julialang.org/u/314)
#### Post date: [May 19, 2021, 1:07pm UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/1 "2021-05-19T13:07:35Z")

</div>

This is my code

```julia
split("hello-world julia", [' ', '-']) .|> 
    x -> filter(isletter, x) .|>
    first .|> 
    uppercase |> 
    join 

```

I want to get the result `"HWJ"`, but I get a

```julia
3-element Vector{String}:
 "H"
 "W"
 "J"

```

When I use the `Pipe` package, the code works fine. The result is `"HWJ"`

```julia
using Pipe
@pipe split("hello-world julia", [' ', '-']) .|> 
    filter(isletter, _) .|>
    first .|> 
    uppercase |> 
    join 

```

and following code always has an error no matter how many parentheses are added

```julia
@pipe split(phrase, [' ', '-']) .|> 
    filter(isletter, _) |> 
    filter(x -> length(x) > 0, _) .|>
    first .|> 
    uppercase |> 
    join 

```

I’m very confused.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [May 19, 2021, 1:55pm UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/2 "2021-05-19T13:55:29Z")

</div>

```julia
julia> split("hello-world julia", [' ', '-']) .|>
           (x -> filter(isletter, x)) .|>
           first .|>
           uppercase |>
           join
"HWJ"

```

anonymous function (`->`) has lower precedence than pipe

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [May 19, 2021, 2:40pm UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/3 "2021-05-19T14:40:28Z")

</div>

I think the Chain.jl syntax is cleaner

```julia
using Chain: @chain

@chain "hello-world julia" begin
    split([' ', '-'])
    filter.(isletter, _)
    first.()
    uppercase.()
    join
end

```

---

<div class="post-metadata">

### Author: ![314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/314/32/25228_2.png) [@314](https://discourse.julialang.org/u/314)
#### Post date: [May 19, 2021, 3:25pm UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/4 "2021-05-19T15:25:33Z")

</div>

Thanks for your help!

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [May 19, 2021, 6:59pm UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/5 "2021-05-19T18:59:02Z")

</div>

There was recently an [announcement](https://discourse.julialang.org/t/ann-datapipes-jl/60734) of new piping package DataPipes.jl by @aplavin.

Wondering if code below is a proper way of writing requested task:

```julia
using DataPipes 
@p begin
    "hello-world julia" |>
    split(_, [' ', '-'])
    filter.(isletter,↑)
    first.(↑)
    uppercase.(↑)
    join
end

```

result seems correct at least: `"HWJ"`

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [May 20, 2021, 12:05am UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/6 "2021-05-20T00:05:23Z")

</div>

Nice. How do you type the \uparrow?

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [May 20, 2021, 12:10am UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/7 "2021-05-20T00:10:48Z")

</div>

I am completely confused by this example

![image](https://global.discourse-cdn.com/julialang/original/3X/d/1/d18568a2050ca8d6666cefa7b91b19641097fe86.png)

No idea what’s going on.

---

<div class="post-metadata">

### Author: ![314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/314/32/25228_2.png) [@314](https://discourse.julialang.org/u/314)
#### Post date: [May 20, 2021, 1:43am UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/8 "2021-05-20T01:43:19Z")

</div>

I think it’s the same with `map(x->(a=x, b=x^2, c=1:x), [1,2,3,4])`, and return a vector of namedtuple

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [May 20, 2021, 2:50am UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/9 "2021-05-20T02:50:38Z")

</div>

so u can skip the `x->`. Don’t feel this is very intuitive. After skimming thru the documentation, it doesn’t seem to explain that.

---

<div class="post-metadata">

### Author: ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)
#### Post date: [May 20, 2021, 8:48am UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/10 "2021-05-20T08:48:38Z")

</div>

The following snippet would be slightly more along the spirit of `DataPipes.jl`:

```julia
@p begin
    split("hello-world julia", [' ', '-'])
    filter.(isletter,↑)
    map(first)
    map(uppercase)
    join
end

```

I haven’t really considered broadcasting as pipeline steps yet, so unlike regular function calls they don’t enjoy automatic substitution of the previous step results.

---

<div class="post-metadata">

### Author: ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)
#### Post date: [May 20, 2021, 8:55am UTC](https://discourse.julialang.org/t/a-confusing-problem-of-pipe/61438/11 "2021-05-20T08:55:20Z")

</div>

> [@xiaodai](#):
>
> Nice. How do you type the \uparrow?

Just type `\uparrow<tab>`, or `\upar<tab><tab>`.

> [@xiaodai](#):
>
> so u can skip the `x->` . Don’t feel this is very intuitive. After skimming thru the documentation, it doesn’t seem to explain that.

This is the whole point of `DataPipes.jl`: to get rid of code overhead when using common data processing functions. Such functions typically take a function as their first argument (or arguments, if multiple), and the dataset as the last argument: think `map/filter/sort/...` in `Base` or `group/join/...` in `SplitApplyCombine`. So, `map(_ + 1)` translates to `map(x -> x + 1, <previous step result>)` and so on.

Agree that the documentation is far from perfect, I just found it easiest for me to put examples showcasing main features instead of extended description.
