【发布时间】:2014-04-08 17:44:43
【问题描述】:
如果我这样做:
val l = Seq(("un", ""), ("deux", "hehe"), ("trois", "lol"))
l map { t => t._1 + t._2 }
没关系。
如果我这样做:
val l = Seq(("un", ""), ("deux", "hehe"), ("trois", "lol"))
l map { case (b, n) => b + n }
没关系。
但如果我这样做:
val l = Seq(("un", ""), ("deux", "hehe"), ("trois", "lol"))
l map { (b, n) => b + n }
它不会起作用。
为什么要使用“case”关键字来使用命名元组?
【问题讨论】:
-
仅供参考,对
case的需求在 Dotty 中消失了,它将在未来的某个时候成为 Scala 3.0。 github.com/lampepfl/dotty/issues/897
标签: scala tuples partialfunction