如何解释Map.map结果 [英] How to explain Map.map result
本文介绍了如何解释Map.map结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我查看 Map.map
scaladoc时,可以看到
When I look a the Map.map
scaladoc, I can see
map[B](f: (A) ⇒ B): Map[B]
但是下面的简单代码不会返回 Map
But the simple following code doesn't return a Map
scala> Map("answer" -> 42).map { case(k, v) => v }
res40: scala.collection.immutable.Iterable[Int] = List(42)
您能解释吗?
推荐答案
Scaladocs是简化的,如果要查看完整的签名,则必须展开并单击显示完整的签名,您会看到真正的签名是这样的:
Scaladocs are simplified, if you want to see the full signature you have to expand and click on show full signature and you'll see that the real one is this:
def map[B, That](f: ((A, B)) ⇒ B)(implicit bf: CanBuildFrom[Map[A, B], B, That]): That
哪个可以返回那个
,可以是 Map
,也可以是列表
。
Which allows to return a That
which can be a Map
but also a List
.
这篇关于如何解释Map.map结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文