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> 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> 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> 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> 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