Rap*_*oth 5 arrays scala tuples
我尝试Array[Double]使用该slice方法切片1D .我写了一个方法,它将开始和结束索引作为元组返回(Int,Int).
def getSliceRange(): (Int,Int) = {
val start = ...
val end = ...
return (start,end)
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能getSliceRange直接使用返回值?
我试过了:
myArray.slice.tupled(getSliceRange())
Run Code Online (Sandbox Code Playgroud)
但这给了我一个编译错误:
Error:(162, 13) missing arguments for method slice in trait IndexedSeqOptimized;
follow this method with `_' if you want to treat it as a partially applied function
myArray.slice.tupled(getSliceRange())
Run Code Online (Sandbox Code Playgroud)
我认为问题是隐式转换Array为ArrayOps(slice来自GenTraversableLike).
val doubleArray = Array(1d, 2, 3, 4)
(doubleArray.slice(_, _)).tupled
Function.tupled[Int, Int, Array[Double]](doubleArray.slice)
(doubleArray.slice: (Int, Int) => Array[Double]).tupled
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
255 次 |
| 最近记录: |