Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to get collection of types what form the union?

Tags:

julia

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]
like image 867
Oleh Devua Avatar asked Jul 27 '15 00:07

Oleh Devua


1 Answers

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.

like image 56
4 revs Avatar answered Sep 24 '22 03:09

4 revs