Reputation: 41909
List#foldLeft
, why is the following Scala 2.11.2 code:
scala> List(1,2,3).foldLeft(2) _ + _
res0: String => String = <function1>
returning a <function1>
?
Additionally, why does the following result equal <function1>5
?
scala> res0("5")
res2: String = <function1>5
Upvotes: 0
Views: 52
Reputation: 4182
I think you've confused the compiler by trying to use infix notation (no parenthesis) and _
placeholders and it's trying to curry it into a function. This works for me:
scala> List(1,2,3).foldLeft(2) (_ + _)
res1: Int = 8
Upvotes: 4