Possible Duplicate:
Applying an argument list to curried function using foldLeft in Scala
Consider:
val f = (i: Int, j: Int, k: Int, l: Int) => i + j + k + l
Because one can do this:
f.curried.apply(1).apply(2).apply(3).apply(4)
It's easy to fall into the trap of trying this:
List(1, 2, 3, 4).foldLeft(f.curried) { (fs, e) => fs.apply(e) }
However, the B
parameter in the fold changes type once one applies an argument to it. In this example, the first iteration would change from a (Int) => (Int) => (Int) => (Int) => Int
to a (Int) => (Int) => (Int) => Int
.
Question: How to solve this?