Skip to content

Instantly share code, notes, and snippets.

@tpolecat
Created August 13, 2013 17:34
Show Gist options
  • Save tpolecat/6223596 to your computer and use it in GitHub Desktop.
Save tpolecat/6223596 to your computer and use it in GitHub Desktop.
object Alg {
sealed trait Num { def toInt: Int }
sealed trait Big extends Num
sealed trait Small extends Num
object Big {
def fromInt(n:Int): Option[Big] =
if (n >= 5) Some(new Big { def toInt = n }) else None
def unapply(n: Big): Some[Int] =
Some(n.toInt)
}
object Small {
def fromInt(n:Int): Option[Small] =
if (n < 5) Some(new Small { def toInt = n }) else None
def unapply(n: Small): Some[Int] =
Some(n.toInt)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment