8

Which are the differences between scan and scanLeft ?

For instance,

(1 to 3).scan(10)(_-_)
res: Vector(10, 9, 7, 4)

(1 to 3).scanLeft(10)(_-_)
res: Vector(10, 9, 7, 4)

deliver the same result, clearly in contrast to

(1 to 3).scanRight(10)(_-_)
res: Vector(-8, 9, -7, 10)
elm
  • 20,117
  • 14
  • 67
  • 113

1 Answers1

7
(1 to 3).par.scanLeft(10)(_-_)
res: scala.collection.parallel.immutable.ParSeq[Int] = ParVector(10, 9, 7, 4)

(1 to 3).par.scanRight(10)(_-_)
res: scala.collection.parallel.immutable.ParSeq[Int] = ParVector(-8, 9, -7, 10)

(1 to 3).par.scan(10)(_-_)
res: scala.collection.parallel.immutable.ParSeq[Int] = ParVector(10, 9, -1, -4)

Basically, it depends on the implementation of the traversable of how scan* (or fold*) is executed.

Debilski
  • 66,976
  • 12
  • 110
  • 133