What is the idiomatic way to take apart a Union type? The obvious structural matching doesn’t do what I expected:
julia> f1(::Type{Union{X, Int64}}) where {X} = X
f1 (generic function with 1 method)
julia> f1(Union{Int64, Float64})
Float64
julia> f2(::Type{Union{X, Float64}}) where {X} = X
f2 (generic function with 1 method)
julia> f2(Union{Int64, Float64})
Int64
julia> f3(::Type{Union{X, Y}}) where {X, Y} = (X, Y)
f3 (generic function with 1 method)
julia> f3(Union{Int64, Float64})
ERROR: UndefVarError: Y not defined
Stacktrace:
[1] f3(::Type{Union{Float64, Int64}}) at ./REPL[7]:1
[2] top-level scope at none:0