Skip to content

Instantly share code, notes, and snippets.

@JavadocMD
Created October 18, 2014 00:27
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 JavadocMD/3c27559c8e90dd30c91a to your computer and use it in GitHub Desktop.
Save JavadocMD/3c27559c8e90dd30c91a to your computer and use it in GitHub Desktop.
case class Foo(val x: Int, val y: Int)
class Bar(val f: Foo, val s: String)
object Bar {
def apply(x: Int, y: Int, s: String): Bar = new Bar(Foo(x, y), s)
def unapply(b: Bar): Option[(Int, Int, String)] = Some((b.f.x, b.f.y, b.s))
}
val a = Bar(1, 2, "A")
a match {
case Bar(x, y, s) => println(x + "" + y + s) // prints "12A"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment