Skip to content

Instantly share code, notes, and snippets.

@dadrox
dadrox / ScalaEnum.scala
Created November 10, 2011 17:40 — forked from viktorklang/ScalaEnum.scala
DIY Scala Enums (with optional exhaustiveness checking, name introspection, boilerplate reverse lookup, and (de)serialization)
// See https://github.com/dadrox/scala.enum for examples in the unit test
trait Enum {
import java.util.concurrent.atomic.AtomicReference
type EnumVal <: Value //This is a type that needs to be found in the implementing class
def withName(name: String): Option[EnumVal] = values.find(_.name == name)
def withNameIgnoringCase(name: String): Option[EnumVal] = values.find(_.name.equalsIgnoreCase(name))