Scala中scan和scanLeft之间的区别

elm*_*elm 7 scala fold scala-collections

哪个是scanscanLeft?之间的区别?

例如,

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

(1 to 3).scanLeft(10)(_-_)
res: Vector(10, 9, 7, 4)
Run Code Online (Sandbox Code Playgroud)

相比之下,结果却相同

(1 to 3).scanRight(10)(_-_)
res: Vector(-8, 9, -7, 10)
Run Code Online (Sandbox Code Playgroud)

Deb*_*ski 6

(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)
Run Code Online (Sandbox Code Playgroud)

基本上,它取决于如何scan*(或fold*)执行的遍历的实现.