Scala Destructuring Bind

val (x,y) = (10, “ten”)

case class T(one:Int, two:String)

val t = T(6,"six"

val T(i,j) = t

val T(a,b) = T(10,"book")

val T(a,_) = T(10,"book")   // ignores the bind of "book"

object Names {
  def unapply(s:String): Option[String] = {
    if( s.trim.startsWith("Mr")) Some(s.trim.drop(2))
    else None
  }
}

val Names(name) = "Mr Jones" // gives "Jones"
05/05/09 at 8:48am