Skip to content

Instantly share code, notes, and snippets.

@hamnis
Created August 3, 2012 17:11
Show Gist options
  • Save hamnis/3249635 to your computer and use it in GitHub Desktop.
Save hamnis/3249635 to your computer and use it in GitHub Desktop.
sealed trait Score {
def isEmpty = this match {
case SetScore(_, _) => false
case NoScore => true
}
def isDefined = !isEmpty
def toOption: Option[(Int, Int)] = this match {
case NoScore => None
case SetScore(home, away) => Some(home -> away)
}
}
case object NoScore extends Score
case class SetScore(home: Int, away: Int) extends Score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment