- Notifications
You must be signed in to change notification settings - Fork0
A single macro package to mix enumerations (or anything that defines a method for Base.instances) and dispatch-on-value in Julia.
License
Klafyvel/InstanceDispatch.jl
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
InstanceDispatch.jl is a single-macro package to mix enumerations (or anything that defines a method forBase.instances) and dispatch-on-value in Julia.
Simply put it allows using dispatching in a type-stable fashion by writing code such as:
using InstanceDispatch@enum GreetEnum Hello Goodbyefunctiongreet(::Val{Hello}, who)return"Hello"* whoendfunctiongreet(::Val{Goodbye}, who)return"Goodbye"* whoend@instancedispatchgreet(::GreetEnum, who)
This last line is equivalent to defining the following method:
functiongreet(e::GreetEnum, who)if e== Helloreturngreet(Val(Hello), who)elseif e== Goodbyereturngreet(Val(Goodbye), who)elseendend
This avoidsthe performance pit that you would encounter in simply writing:
functiongreet(e::GreetEnum, who)returngreet(Val(e), who)end
import Pkg; Pkg.add("InstanceDispatch")
- ValSplit.jl essentially performs the same task for
Symbol-based value type dispatch.
About
A single macro package to mix enumerations (or anything that defines a method for Base.instances) and dispatch-on-value in Julia.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors3
Uh oh!
There was an error while loading.Please reload this page.