API

DynamicSumTypes.@sumtypeMacro
@sumtype SumTypeName(Types) [<: AbstractType]

The macro creates a sumtypes composed by the given types. It optionally accept also an abstract supertype.

Example

julia> using DynamicSumTypes

julia> struct A x::Int end;

julia> struct B end;

julia> @sumtype AB(A, B)
DynamicSumTypes.variantFunction
variant(inst)

Returns the variant enclosed in the sum type.

Example

julia> using DynamicSumTypes

julia> struct A x::Int end;

julia> struct B end;

julia> @sumtype AB(A, B)

julia> a = AB(A(0))
AB'.A(0)

julia> variant(a)
A(0)
DynamicSumTypes.allvariantsFunction
allvariants(SumType)

Returns all the enclosed variants types in the sum type in a namedtuple.

Example

julia> using DynamicSumTypes

julia> struct A x::Int end;

julia> struct B end;

julia> @sumtype AB(A, B)

julia> allvariants(AB)
(A = A, B = B)