Enumex.Static.Components.Constant (Enumex v1.0.0)
View SourceA component that generates constant functions for each enum value.
Constant functions
Functions with the following naming would be generated:
const_#{enum_name}_#{id}
- returns theEnumex.Value
structconst_#{enum_name}_#{index}
- returns theEnumex.Value
structconst_id_#{enum_name}_#{index}
- returns id of the enum valueconst_index_#{enum_name}_#{id}
- returns index of the enum value
Example
defmodule MyApp.Enums do
use Enumex.Static, components: [Enumex.Static.Components.Constant]
# enum definitions go here
end
iex> MyApp.Enums.const_my_enum_1()
Enumex.Value.new(MyApp.Enums, :my_enum, :first, 1)
iex> MyApp.Enums.const_my_enum_first()
Enumex.Value.new(MyApp.Enums, :my_enum, :first, 1)
iex> MyApp.Enums.const_my_enum_id_1()
:first
iex> MyApp.Enums.const_my_enum_index_first()
1