SumTypes.isvariant
— Functionisvariant(x::SumType, s::Symbol)
For an x
which was created as a @sum_type
, check if it's variant tag is s
. e.g.
@sum_type Either{L, R} begin
Left{L}(::L)
Right{R}(::R)
end
let x::Either{Int, Int} = Left(1)
isvariant(x, :Left) # true
isvariant(x, :Right) # false
end