此代码来自使用Scala的模式匹配查询数据集:
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)"
Run Code Online (Sandbox Code Playgroud)
&实际上如何运作?我没有在连词的任何地方看到布尔测试.这个Scala魔法是如何工作的?
scala ×1