Enuma (Enuma v0.1.0)
View SourceEnuma is a library for defining and working with Rust like Enums in Elixir.
Example
defmodule MyEnum do
use Enuma
defenum do
item :foo
item :bar, args: [integer()]
item :baz, args: [String.t()]
end
end
Enuma will create macros for each item, allowing you to match on the enum values and check if a value is of a specific type.
iex> require MyEnum
MyEnum
iex> MyEnum.foo() = :foo
true
iex> MyEnum.bar(x) = {:bar, 1}
{:bar, 1}
It will also generate macros for checking if a value is of a specific type. (e.g MyEnum.is_foo(value)
).
These macros can be used in pattern matching and guards.