API

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

Creates a sumtype composed by the given types. It optionally accept also an abstract supertype.

Example

julia> using LightSumTypes

julia> struct A x::Int end;

julia> struct B end;

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

Returns the variant enclosed in the sum type.

Example

julia> using LightSumTypes

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)
source
LightSumTypes.allvariantsFunction
allvariants(SumType)

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

Example

julia> using LightSumTypes

julia> struct A x::Int end;

julia> struct B end;

julia> @sumtype AB(A, B)

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