Skip to content

Instantly share code, notes, and snippets.

@vrotaru
Last active Apr 25, 2017
Embed
What would you like to do?
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