Difference between scan and scanLeft in Scala

What 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) 

gives the same result, clearly unlike

 (1 to 3).scanRight(10)(_-_) res: Vector(-8, 9, -7, 10) 
+6
source share
1 answer
 (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 passing scan* (or fold* ) process.

+5
source

Source: https://habr.com/ru/post/975396/


All Articles