【问题标题】:Difference between scan and scanLeft in Scala [duplicate]Scala中scan和scanLeft之间的区别[重复]
【发布时间】:2014-09-17 07:03:57
【问题描述】:

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)

【问题讨论】:

    标签: scala scala-collections fold


    【解决方案1】:
    (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*)如何执行的可遍历的实现。

    【讨论】:

      猜你喜欢
      • 2011-11-16
      • 2013-06-16
      • 2014-09-14
      • 2012-11-19
      • 2014-08-16
      • 2011-04-08
      • 2012-11-24
      • 2013-06-05
      相关资源
      最近更新 更多