Last active
April 25, 2017 13:14
-
-
Save vrotaru/d59275747c7d3a0c99877772da328090 to your computer and use it in GitHub Desktop.
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
trait A | |
case object a extends A | |
case object b extends A | |
trait B | |
case object x extends B | |
case object y extends B | |
object A { | |
def apply(arg: B): A = arg match { | |
case x => a | |
case y => b | |
} | |
def unapply(arg: A): Option[B] = arg match { | |
case a => Some(x) | |
case b => Some(y) | |
case _ => None | |
} | |
} | |
object Unapply { | |
def main(args: Array[String]): Unit = { | |
val arg: A = a | |
arg match { | |
case x => println("x") | |
case y => println("y") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment