# Mid-chain array comprehensions affect (join) broadcasting behavior?

**URL:** https://discourse.julialang.org/t/mid-chain-array-comprehensions-affect-join-broadcasting-behavior/81829
**Category:** General Usage
**Tags:** piping
**Created:** [May 28, 2022, 10:36am UTC](https://discourse.julialang.org/t/mid-chain-array-comprehensions-affect-join-broadcasting-behavior/81829 "2022-05-28T10:36:36Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![kostas-emman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kostas-emman/32/27246_2.png) [@kostas-emman](https://discourse.julialang.org/u/kostas-emman)
#### Post date: [May 28, 2022, 10:36am UTC](https://discourse.julialang.org/t/mid-chain-array-comprehensions-affect-join-broadcasting-behavior/81829/1 "2022-05-28T10:36:36Z")

</div>

I could do what is presented here in a different way (e.g. using replace) but please bear with me since I am more interested in the intuition behind the behavior presented below.

I use Julia 1.7.3.

If I have a 2-element Vector{Vector{Char}} and want to transform the sub-vectors in strings, I can do the below:

```julia
julia> arr = [['d', 'a'], ['a', 'd']]
2-element Vector{Vector{Char}}:
 ['d', 'a']
 ['a', 'd']

julia> arr .|> join
2-element Vector{String}:
 "da"
 "ad"

```

However, if I want to first make a mapping (using comprehensions), the result of the final join changes (even if the output from the transformation is still a 2-element Vector{Vector{Char}}.

Specifically:

```julia
julia> mappings = Dict('a'=> '1', 'd'=> '2')
Dict{Char, Char} with 2 entries:
  'a' => '1'
  'd' => '2'

julia> arr .|> v -> [mappings[c] for c in v] .|> join
2-element Vector{Vector{String}}:
 ["2", "1"]
 ["1", "2"]

```

In order to make each sub-vector into a string, I need to drop the broadcasting for the join.

```julia
julia> arr .|> v -> [mappings[c] for c in v] |> join
2-element Vector{String}:
 "21"
 "12"

```

But, I still need to use it if I perform the join in a separate step on the transformed Vector.

```julia
julia> mapped_arr = arr .|> v -> [mappings[c] for c in v]
2-element Vector{Vector{Char}}:
 ['2', '1']
 ['1', '2']

julia> mapped_arr .|> join
2-element Vector{String}:
 "21"
 "12"

```

I suspect it could be the way piping works but still I find it odd.

I would appreciate any thoughts or an explanation that would make this behavior more clear.

Thank you
