例如,
scala> val a = Set(Array(1, 2),Array(8, 9))
a: scala.collection.immutable.Set[Array[Int]] = Set(Array(1, 2), Array(8, 9))
scala> a.flatMap(_)
<console>:9: error: missing parameter type for expanded function ((x$1) => a.flatMap(x$1))
a.flatMap(_)
^
scala> a.flatMap(x=>x)
res4: scala.collection.immutable.Set[Int] = Set(1, 2, 8, 9)
x=>x
lambda函数类型是否有快捷方式?
看来您正在寻找identity
,
val a = Set(Array(1, 2) ,Array(8, 9))
a.flatten
a.map(identity).flatten
如果你认同自己的身份
@inline def identity[A](x: A): A = x
因此它的作用与相同x => x
,无论返回的结果如何。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句