Explain this pattern matching code

Viewed 1580

This code is from Querying a Dataset with Scala's Pattern Matching:

object & { def unapply[A](a: A) = Some((a, a)) }

"Julie" match {
  case Brothers(_) & Sisters(_) => "Julie has both brother(s) and sister(s)"
  case Siblings(_) => "Julie's siblings are all the same sex"
  case _ => "Julie has no siblings"
}

// => "Julie has both brother(s) and sister(s)"

How does & actually work? I don't see a Boolean test anywhere for the conjunction. How does this Scala magic work?

3 Answers
Related