List#foldLeft
,为什么以下Scala 2.11.2代码:
scala> List(1,2,3).foldLeft(2) _ + _
res0: String => String = <function1>
返回<function1>
?
此外,为什么以下结果等于<function1>5
?
scala> res0("5")
res2: String = <function1>5
答案 0 :(得分:4)
我认为您通过尝试使用中缀符号(无括号)和_
占位符来混淆编译器,并且它试图将其编入函数中。这对我有用:
scala> List(1,2,3).foldLeft(2) (_ + _)
res1: Int = 8