github AVSystem/scala-commons v1.24.1

latest releases: v2.16.0, v2.15.0, v2.14.0...
6 years ago

ValueEnum

ValueEnum is a new way for defining Scala enums, representing enum constants as final vals in companion object of enum class.

Advantages:

  • feature parity with Java enums (although ValueEnum does not extend java.lang.Enum)
  • every enum constant has name (name of the final val that declares the constant) and ordinal (zero based index of enum constant, consistent with declaration order).
  • less boilerplate than sealed hierarchy based enums
  • it's possible to declare many enum constants in a single line of code
  • much less generated classes, which is advantageous primarily for JS size reduction

Disadvantages:

  • scalac exhaustive pattern match checking does not understand ValueEnum which may result in both lack of correct warnings and incorrect warnings
  • each enum constant can't have its own API (unless through implicit classes)

Don't miss a new scala-commons release

NewReleases is sending notifications on new releases.