I read in a csv file and I want to generate types based on the content.
My idea was to build a lookup dictionary for this, however the subtypes
function only exists in InteractiveUtils.jl. I would like to avoid including this in my package.
How do I avoid using subtypes to build a save translation of string/symbols to types.
The current code looks like this:
function build_lookup_dict(abstract_type)
types = subtypes(abstract_type)
return Dict(nameof.(types) .=> types)
end
abstract type myabstracttype end
struct mytype1 <: myabstracttype end
struct mytype2 <: myabstracttype end
#----------
julia> input = " mytype1"
" mytype1"
julia> dict = build_lookup_dict(myabstracttype)
Dict{Symbol, DataType} with 2 entries:
:mytype1 => mytype1
:mytype2 => mytype2
julia> dict[Symbol.(strip(input))]
mytype1