What is the best pattern to create literal types in Julia?
In Typescript, you can make types out of string literals:
type command = "start" | "end" | "pause";
In Julia, this would allow you to use multiple-dispatch with string arguments, making it easy to extend cases.
An example of this would look like
function process(::"start")
initialize()
do_something()
...
end
function process(::"end")
teardown()
...
end
function process(::"pause")
temporary_pause()
...
end
Currently, I am using a workaround similar to this
struct CommandType{T}
end
CommandType(s::AbstractString) = CommandType{Symbol(s)}()
macro CommandType_str(s)
return CommandType{Symbol(s)}
end
function process(t::CommandType"start")
...
end
function process(t::CommandType"stop")
...
end
function process(t::CommandType"pause")
...
end
process(command::String) = process(CommandType(command))
# Usage
process("start")
Is there a more succinct pattern I can use? Is it possible that literal types will be added to Julia in the near future?