# Join() on iterator containing missing returns string containing "missing"

**URL:** <https://discourse.julialang.org/t/join-on-iterator-containing-missing-returns-string-containing-missing/116623>\
**Category:** General Usage\
**Created:** [July 4, 2024, 11:48am UTC](https://discourse.julialang.org/t/join-on-iterator-containing-missing-returns-string-containing-missing/116623 "2024-07-04T11:48:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flxho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/flxho/32/3922_2.png) [@flxho](https://discourse.julialang.org/u/flxho)\
**Post date:** [July 4, 2024, 11:48am UTC](https://discourse.julialang.org/t/join-on-iterator-containing-missing-returns-string-containing-missing/116623/1 "2024-07-04T11:48:24Z")

</div>

When executing `join([missing])`, the result is the String `"missing"`. Is this intended behavior? I would have expected `missing` as a result. Is this by intention?

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [July 4, 2024, 12:07pm UTC](https://discourse.julialang.org/t/join-on-iterator-containing-missing-returns-string-containing-missing/116623/2 "2024-07-04T12:07:49Z")

</div>

> [@flxho](#):
>
> Is this intended behavior?

I think so:

```julia-repl
help?> join
search: join joinpath adjoint typejoin isdisjoint

  join([io::IO,] iterator [, delim [, last]])

  Join any iterator into a single string, inserting the given delimiter (if
  any) between adjacent items. If last is given, it will be used instead of
  delim between the last two items. Each item of iterator is converted to a
  string via print(io::IOBuffer, x). If io is given, the result is written to
  io rather than returned as a String.

  Examples
  ≡≡≡≡≡≡≡≡

  julia> join(["apples", "bananas", "pineapples"], ", ", " and ")
  "apples, bananas and pineapples"
  
  julia> join([1,2,3,4,5])
  "12345"

```

and `print(missing)` just prints “missing”, which makes sense, since you would not see any output in the REPL otherwise.  
Perhaps you’d like something more like:

```julia-repl
julia> mystring(x) = string(x)
mystring (generic function with 1 method)

julia> mystring(::Missing) = missing
mystring (generic function with 2 methods)

julia> mapreduce(mystring, *, [1,2,3,missing])
missing

```

Just note that this much more inefficient (like O(N^2) scaling) when concatenating strings.  
Other idea:

```julia-repl
julia> myjoin(itr) = any(ismissing, itr) ? missing : join(itr)
myjoin (generic function with 1 method)

julia> myjoin([1,2,3,missing])
missing

```
