Difference between fold and foldLeft or foldRight?

前端 未结 7 1771
星月不相逢
星月不相逢 2020-11-29 20:43

NOTE: I am on Scala 2.8—can that be a problem?

Why can\'t I use the fold function the same way as foldLeft or foldRight?

7条回答
  •  粉色の甜心
    2020-11-29 21:30

    fold, contrary to foldRight and foldLeft, does not offer any guarantee about the order in which the elements of the collection will be processed. You'll probably want to use fold, with its more constrained signature, with parallel collections, where the lack of guaranteed processing order helps the parallel collection implements folding in a parallel way. The reason for changing the signature is similar: with the additional constraints, it's easier to make a parallel fold.

提交回复
热议问题