Skip to content

Instantly share code, notes, and snippets.

@vrotaru
Last active April 25, 2017 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrotaru/d59275747c7d3a0c99877772da328090 to your computer and use it in GitHub Desktop.
Save vrotaru/d59275747c7d3a0c99877772da328090 to your computer and use it in GitHub Desktop.
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