Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.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嵌套通配符占位符_Scala - Fatal编程技术网

Scala嵌套通配符占位符

Scala嵌套通配符占位符,scala,Scala,我有一个用Scala制作的二维数组 val arr = Array(Array()) 我想用期权把它安全地提取出来。我想使用通配符,但尽管如此: def get(x:Int, y: Int) = arr lift x flatMap { _ lift y map { a=>a } } 这并不重要 def get(x:Int, y: Int) = arr lift x flatMap { _ lift y map { _ } } 谁能给我解释一下区别是什么吗?\u本身并没有扩展到x=>

我有一个用Scala制作的二维数组

val arr = Array(Array())
我想用期权把它安全地提取出来。我想使用通配符,但尽管如此:

def get(x:Int, y: Int) = arr lift x flatMap { _ lift y map { a=>a } }
这并不重要

def get(x:Int, y: Int) = arr lift x flatMap { _ lift y map { _ } }

谁能给我解释一下区别是什么吗?

\u
本身并没有扩展到
x=>x
identity

您可能希望使用的是
标识
predef:

def get(x: Int, y: Int) = arr lift x flatMap { _ lift y map {identity} }

参见第6.23.1节。

为什么您需要在末尾执行额外的
map
操作?看起来你所需要的就是
\uuy
哇。你说得对!我只是把地图放得太长了