Applying an argument list to curried function using foldLeft in Scala

前端 未结 3 1326
耶瑟儿~
耶瑟儿~ 2020-12-01 12:41

Is it possible to do a foldLeft on a list of arguments, where the initial value supplied to the fold is a fully curried function, the operator is apply

3条回答
  •  借酒劲吻你
    2020-12-01 13:03

    Ok no scalaz and no solution but an explanation. If you use your f.curried.apply with 1 and then with 2 arguments in the REPL observe the return-result types DO actually differ each time! FoldLeft is quite simple. It's fixed in it's type with your starting argument which is f.curried and since that has not the same signature as f.curried.apply(1) it doesn't work. So the starting argument and the result HAVE to be of the same type. The type hast to be consistent for the starting-sum element of foldLeft. And your result would be even Int so that would absolutely not work. Hope this helps.

提交回复
热议问题