Hi everyone,
I have just published the first version of a library that I have been using in my projects for over a year now: SimpleEnum - a simple library that implements Enumerations in Elixir.
SimpleEnum was designed to be :
- fast: being based on a macro system, access to the Enum will be resolved at compile time when it is possible
- simple: the use of the library has been designed to be as simple as possible for a developer to use. In addition to providing Enums, it automatically defines their types and provides an introspection system.
Examples of uses can be found in the documentation : SimpleEnum — simple_enum v0.1.0
Proposals :
To improve SimpleEnum, I had several ideas like
- Add the
defenump
function in order to create private Enums: currently, all Enums are public - Add an
EnumValueError
exception for developers who needrescue
. Currently,ArgumentError
is used - Add a decorator
@allow_duplicate_values true
or@unique false
to allow duplicates values in Enum - Add macros
is_enum/1
,is_enum_key/1
andis_enum_value/1
(eg.is_color(:red)
,is_color_key(:red)
andis_color_value(:red)
) for each Enum. An example of implementation can be found here.
What do you think? Would you need a feature in the list or another one?
Any issues, suggestions or contributions are welcome.
Cheers
Links:
- Hex.pm page: https://hex.pm/packages/simple_enum
- Documentation: https://hexdocs.pm/simple_enum
- Source code: https://github.com/ImNotAVirus/simple_enum