我写了以下内容
def mapFun[T, U](xs: List[T], f: T => U): List[U] = (xs foldRight List[U]())( f(_)::_ )
当我这样做时
def f(x: Int):Int=x*x
mapFun(List(1,2,3), f)
它运行良好。然而,我真的想让以下内容也能够工作
mapFun(List(1,2,3), x=>x*x)
它抱怨缺少参数类型。我知道可以使用柯里化,但是否仍有办法为上述非柯里化def使用匿名函数?
mapFun[Int, Int](List(1,2,3), x => x * x)
- Dominic Bou-Samra