Lui*_*hys 9 scala pattern-matching
例如,如果我想写
1 -> 2 match {
  case 1 -> 2 => "matched"
  case _      => "not matched"
}
// error: not found: value ->
而不是稍微不那么明显
1 -> 2 match {
  case (1, 2) => "matched"
  case _      => "not matched"
}
dhg*_*dhg 15
我有这样的事情!我喜欢它,因为在很多情况下我发现它更具可读性.
object -> {
  def unapply[A, B](pair: (A, B)): Option[(A, B)] =
    Some(pair)
}
现在你可以这样做:
scala> val a -> b = 1 -> 2
a: Int = 1
b: Int = 2