Skip to content

Instantly share code, notes, and snippets.

@ryanpbrewster
Created January 23, 2016 00:48
Show Gist options
  • Save ryanpbrewster/29bfaf3b8b97821504b8 to your computer and use it in GitHub Desktop.
Save ryanpbrewster/29bfaf3b8b97821504b8 to your computer and use it in GitHub Desktop.
class Foo {
sealed trait A
case class A1(x: Int) extends A
case class A2(y: String) extends A
case class A3(z: Double) extends A
sealed trait B
case class B1(z: Int) extends B
case class B2(z1: Int) extends B
case class Carrier(a: A, b: B)
def foo(c: Carrier): Unit = c match {
case Carrier(A1(x), B1(y)) => println(x + y)
}
def bar(a: A, b: B): Unit = (a, b) match {
case (A1(x), _) => println(x)
case (A2(y), _) => println(y)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment