Created
August 13, 2013 17:34
-
-
Save tpolecat/6223596 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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