InstanceDispatch
Documentation for InstanceDispatch.
InstanceDispatch.@instancedispatch
— Macro@instancedispatch myfunction(::T, args...; kwargs...)
Write a specialized function to dispatch on instances values of type T
. The only reauirement is that Type{T}
has its own method for Base.instances
.
Examples
@enum GreetEnum Hello Goodbye
function greet(::Val{Hello}, who)
return "Hello " * who
end
function greet(::Val{Goodbye}, who)
return "Goodbye " * who
end
@instancedispatch greet(::GreetEnum, who)
This last line is equivalent to defining the following method:
function greet(e::GreetEnum, who)
if e == Hello
return greet(Val(Hello), who)
elseif e == Goodbye
return greet(Val(Goodbye), who)
else end
end