我能够做到这一点:
def largestAt(fun: (Int) => Int, inputs: Seq[Int]):Int = {
inputs.reduceLeft(math.max(_,_))
}
但是,当我尝试这样做时:
def largestAt(fun: (Int) => Int, inputs: Seq[Int]):Int = {
inputs.reduceLeft(math.max(fun(_),fun(_)))
}
我收到下面提到的编译错误:
overloaded method value max with alternatives:
[error] (x: Double,y: Double)Double <and>
[error] (x: Float,y: Float)Float <and>
[error] (x: Long,y: Long)Long <and>
[error] (x: Int,y: Int)Int
[error] cannot be applied to (Int => Int, Int => Int)
[error] inputs.reduceLeft(math.max(fun(_),fun(_)))
我只想传递fun
tomath.max
调用的结果。我怎样才能做到这一点。
提前致谢...