This question already has answers here:
Difference between fold and foldLeft or foldRight?

(7个答案)


已关闭6年。



scanscanLeft有什么区别?

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

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

提供相同的结果,显然与
(1 to 3).scanRight(10)(_-_)
res: Vector(-8, 9, -7, 10)

最佳答案

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

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

关于scala - Scala中scan和scanLeft之间的区别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25884279/

10-09 03:14