如果我想写
1 -> 2 match { case 1 -> 2 => "matched" case _ => "not matched" } // error: not found: value ->
而不是稍微不那么明显
1 -> 2 match { case (1, 2) => "matched" case _ => "not matched" }我只有这样的事情!我喜欢它,因为我发现它在许多情况下更易读.
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
精彩评论