blob: 7f2a8818c0fc264c6920f5377092dd2c564d69fc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package generic
import Shapes._
/** enum Color {
* case Red
* case Green
* case Blue
* }
*/
sealed trait Color extends Enum
object Color {
private val $values = new runtime.EnumValues[Color]
def valueOf = $values.fromInt
def withName = $values.fromName
def values = $values.values
private def $new(tag: Int, name: String) = new Color {
def enumTag = tag
override def toString = name
$values.register(this)
}
val Red: Color = $new(0, "Red")
val Green: Color = $new(1, "Green")
val Blue: Color = $new(2, "Blue")
implicit val ColorShape: Color `shaped` EnumValue[Color] =
new (Color `shaped` EnumValue[Color]) {
def toShape(x: Color) = EnumValue(x.enumTag)
def fromShape(x: EnumValue[Color]) = Color.valueOf(x.tag)
}
}
|