I frequently have a design pattern of Union{Title, Void}. I was thinking 
that I could redefine this as title::Nullable{Title}. However, once I try 
to modify fields inside the Title type using setfield!(ec.title, k, v), I 
get this error message:

LoadError: type Nullable is immutable
while loading In[19], in expression starting on line 4



My question is, why is the Nullable type immutable? My original thought was 
that my Nullable definition was saying "There is either a Title type here 
or nothing/missing", and maybe I know the value now or maybe I know it 
later. But it seems the definition is actually "There could be a Title type 
here or missing, and whatever you see first is what you will always have"

Is there a better way to express the former behavior other than as a Union 
type? My use case is building JSON strings as specifications of graphs for 
JavaScript libraries, so nearly every field of every type is possibly 
missing for any given specification.

@with_kw type EChart <: AbstractEChartType
    # title::Union{Title,Void} = Title()
    title::Nullable{Title} = Title()
    legend::Union{Legend,Void} = nothing
    grid::Union{Grid,Void} = nothing
    xAxis::Union{Array{Axis,1},Void} = nothing
    yAxis::Union{Array{Axis,1},Void} = nothing
    polar::Union{Polar,Void} = nothing
    radiusAxis::Union{RadiusAxis,Void} = nothing
    angleAxis::Union{AngleAxis,Void} = nothing
    radar::Union{Radar,Void} = nothing
    dataZoom::Union{DataZoom,Void} = nothing
    visualMap::Union{VisualMap,Void} = nothing
    tooltip::Union{Tooltip,Void} = nothing
    toolbox::Union{Toolbox,Void} = Toolbox()
    geo::Union{Geo,Void} = nothing
    parallel::Union{Parallel,Void} = nothing
    parallelAxis::Union{ParallelAxis,Void} = nothing
    timeline::Union{Timeline,Void} = nothing
    series::Union{Array{Series,1},Void} = nothing
    color::Union{AbstractVector,Void} = nothing
    backgroundColor::Union{String,Void} = nothing
    textStyle::Union{TextStyle,Void} = nothing
    animation::Union{Bool,Void} = nothing
    animationDuration::Union{Int,Void} = nothing
    animationEasing::Union{String,Void} = nothing
    animationDelay::Union{Int,Void} = nothing
    animationDurationUpdate::Union{Int,Void} = nothing
    animationEasingUpdate::Union{String,Void} = nothing
    animationDelayUpdate::Union{Int,Void} = nothing
end

Reply via email to