Let's say I have the Union
:
SomeUnion = Union{Int, String}
Is there a method to extract a collection of types that form this union? For example ....
union_types(SomeUnion) # => [Int, String]
just write down a simple example here:
a = Union(Int,String)
function union_types(x)
return x.types
end
julia> union_types(a)
(Int64,String)
you can store the result into an array if you want:
function union_types(x)
return collect(DataType, x.types)
end
julia> union_types(a)
2-element Array{DataType,1}:
Int64
String
UPDATE: use collect
as @Luc Danton suggested in comment below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With