During the development of a package I needed some reflective informations of a Union datatype. I used the following formulation:
Optional{T} = Union{Nothing, T}
struct Address
street::String
town::String
end
struct TestStruct
address::Optional{Address}
end
in one of the package functions I need to know which Type besides Nothing is inside the Union type. For this I used Base.uniontypes. My question is now: Is there any other way to get the datatypes besides what I used and is it appropriate to use non exported functions if they fits very well?
Opinions and suggestions are highly appreciated.
Well, I’ve tried your suggestion but I get only the Union type back. What I’m Interested in is the type T itself. I you use your suggestion you will get the following:
f(::Optional{T}) where {T} = T with Optional{String} gives Union and I’m interested in String.