Fold and foldLeft method difference

后端 未结 7 806
终归单人心
终归单人心 2021-01-31 01:51

I am not sure what is the difference between fold and foldLeft in Scala.

The question Difference between fold and foldLeft or foldRight? has an

7条回答
  •  走了就别回头了
    2021-01-31 02:13

    It has been mentioned, but without example: If you want to allow parallelism with different data types for output and input, you could use aggregate:

    Array("1","2","3").aggregate(0)(_ + _.toInt, _ + _)
    

    The first function gets called first. Its results are then reduced with the second function. See Explanation of the aggregate scala function.

提交回复
热议问题