Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between scan and scanLeft in Scala [duplicate]

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)
like image 485
elm Avatar asked Sep 17 '14 07:09

elm


1 Answers

(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.

like image 180
Debilski Avatar answered Nov 13 '22 06:11

Debilski