Created
December 27, 2010 11:11
-
-
Save mrico/756051 to your computer and use it in GitHub Desktop.
Question about Record's EnumField and Enumeration types
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 net.liftweb._ | |
import record._ | |
import record.field._ | |
object State extends State | |
sealed abstract class State extends Enumeration("created", "destroyed") { | |
type State = Value | |
val Created, Destroyed = Value | |
} | |
class Thing extends Record[Thing] { | |
def meta = Thing | |
object state extends EnumField(this, State, State.Created) | |
} | |
object Thing extends Thing with MetaRecord[Thing] | |
object Test { | |
def switch(state: State#Value) = | |
if(state == State.Created) State.Destroyed else State.Created | |
val thing = Thing.createRecord | |
thing.state.set(State.Created) | |
switch(thing.state.is) == switch(State.Destroyed) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment