Some time ago I posted about a simple code generation tool to help alleviate the overhead/boilerplate when using custom types as simple enum-like types.
It was called elm-enums and given a set of definitions allows the automatic generation of Elm code for the type itself as well as JSON encoders and decoders.
I don’t know if anyone other than myself actually uses it (!), but just in case they do I wanted to let you know that it has now been updated to also generate stringifiers and value lists for enum-like types.
For example, given the following defenition:
enum DogBreeds =
[ Alsatian
, Labrador
, Retriever
, Collie
...
]
elm-enums will generate Elm code for you that defines a custom type called DogBreeds as well as JSON encoders/decoders called encodeDogBreeds/decodeDogBreeds, a stringifier stringifyDogBreeds that converts a value of type DogBreed to a String and listAllDogBreeds that returns a List DogBreeds containing all possible values of the type. If you need to update the type then you just update the definition and rerun elm-enums and all these functions will be updated for you without you needing to write/edit any other code.
As before it is available to install via npm with npm install -g elm-enums.