给出以下输入:
scala> val as = List(Array(1,2,3), Array(10,20,30), Array(100,200,300))
as: List[Array[Int]] = List(Array(1, 2, 3), Array(10, 20, 30), Array(100, 200, 300))
我想知道为什么会这样:
示例 1
scala> as.reduce((x,y) => x)
res65: Array[Int] = Array(1, 2, 3)
但是这个看似相同的东西不起作用:
示例 2
scala> as.reduce{case(x,y) => x}
<console>:13: error: missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: (?, ?) => ?
as.reduce{case(x,y) => x}
任何人都可以解释为什么第一个示例有效但第二个示例无效?
最佳答案
关于scala 内联函数 - "ar.reduce((x,y) => x)"有效,但 "ar.reduce{case(x,y) => x}"无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42799253/