Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有类型参数的Scala flatMap函数语法_Scala - Fatal编程技术网

带有类型参数的Scala flatMap函数语法

带有类型参数的Scala flatMap函数语法,scala,Scala,根据API,函数签名是def flatMap[B](f:(A)⇒ GenTraversableOnce[B]:列出[B],其中B是返回集合的元素类型 那为什么不呢 valxs=Map(“a”->List(11111),“b”->List(22222)).flatMap[Int](\uu.\u2)compile?它给出了一个“错误的方法类型参数数”错误,似乎表明签名与API文档中的签名不同?是的,API文档中给出的签名是为了隐藏隐式的CanBuildFrom参数,因为它让人不安。单击方法文档底部的

根据API,函数签名是
def flatMap[B](f:(A)⇒ GenTraversableOnce[B]:列出[B]
,其中B是返回集合的元素类型

那为什么不呢
valxs=Map(“a”->List(11111),“b”->List(22222)).flatMap[Int](\uu.\u2)
compile?它给出了一个“错误的方法类型参数数”错误,似乎表明签名与API文档中的签名不同?

是的,API文档中给出的签名是为了隐藏隐式的
CanBuildFrom
参数,因为它让人不安。单击方法文档底部的“完整签名”以查看实际签名:

def flatMap[B, That](f: ((A, B)) ⇒ GenTraversableOnce[B])
                    (implicit bf: CanBuildFrom[Map[A, B], B, That]): That 
在这种情况下,您可以不使用type参数

scala> val xs = Map("a" -> List(11,111), "b" -> List(22,222)).flatMap(_._2)
xs: scala.collection.immutable.Iterable[Int] = List(11, 111, 22, 222)