Consider this code:
julia> bar(::Nothing) = missing
bar (generic function with 1 method)
julia> bar(x) = x;
julia> xs = [1, 2, nothing, 4]
4-element Vector{Union{Nothing, Int64}}:
1
2
nothing
4
julia> ys = map(bar, xs)
4-element Vector{Union{Missing, Int64}}:
1
2
missing
4
We can see we get a nice array of small unions in the output.
But if I make my own similar singleton type, then the output is a Array{Any}
.
julia> struct Null end
julia> foo(::Nothing) = Null();
julia> foo(x) = x;
julia> xs = [1, 2, nothing, 4]
4-element Vector{Union{Nothing, Int64}}:
1
2
nothing
4
julia> ys = map(foo, xs)
4-element Vector{Any}:
1
2
Null()
4
Is there something extra i need to do, or is the compiler cheating for Missing
and Nothing
?