Scala – Enumeratum
Enumeratum is a third party enumeration library for Scala. It is also probably the most used enumeration library amongst all scala developers. It is also quite similar to Scala enumerations so using it is quite easy. To start using enumeratum, it needs to be imported into the Scala project. In the build.sbt add the following. See Below Using enumeratum is pretty simple. See Below Let’s go thru the code line by line The first line to look at is the import enumeratum._ which is pretty self-explanatory. The next line sealed trait Color extends EnumEntry creates a sealed trait called Color which extends an enumeratum trait called EnumEntry. findValues is a protected method which invokes a macro Finally, we have our Enum values. Enumeratum provides methods similar to Scala enumerations library for checking index, retrieving a list of values. Additional attributes can be added to the enumerations using enumeratum. See Below … Read more