-
-
Save lloydmeta/256b46847d4b687ff69f341b5e69149b to your computer and use it in GitHub Desktop.
Ammonite usage of generic Enum[T]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ import $ivy.`com.beachape::enumeratum:1.5.12`, enumeratum._ | |
import $ivy.$ , enumeratum._ | |
@ class EntryGetter[T <: EnumEntry: Enum] { | |
// materialise the Enum[T] and bind it (available via Enum.materializeEnum) | |
private val enumCompanion = implicitly[Enum[T]] | |
def getEntry(name: String): T = enumCompanion.withName(name) | |
} | |
defined class EntryGetter | |
@ { | |
sealed trait Light extends EnumEntry | |
object Light extends Enum[Light] { | |
val values = findValues | |
case object Red extends Light | |
case object Yellow extends Light | |
case object Green extends Light | |
} | |
} | |
defined trait Light | |
defined object Light | |
@ val getter = new EntryGetter[Light] | |
getter: EntryGetter[Light] = ammonite.$sess.cmd1$EntryGetter@74f92d14 | |
@ println(getter.getEntry("Red")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment