1

I timed the the following two, and it appears that both of them take the same amount of time. Is there any benefit of using over the other?

(1 to 24).foldRight(List[Int]())((i, l) => l ::: generateList(signs, i))

vs.

(1 to 24).map(i => generateList(signs, i)).reduce(_ ::: _)

p.s. in my use case the order does not matter.

Saqib Ali
  • 3,953
  • 10
  • 55
  • 100
  • 2
    Possible duplicate of [Difference between reduce and foldLeft/fold in functional programming (particularly Scala and Scala APIs)?](http://stackoverflow.com/questions/25158780/difference-between-reduce-and-foldleft-fold-in-functional-programming-particula) – marios Jul 04 '16 at 00:28

1 Answers1

4

foldRight operates in order, map is (theoretically) parallelizable because it's order is not defined. I do not believe that it is parallel in the current scala runtime- just that it might be in the future or on different platforms.

Chris Shain
  • 50,833
  • 6
  • 93
  • 125
  • 2
    `someCollection.par` is parallelizable where possible (http://docs.scala-lang.org/overviews/parallel-collections/overview.html) – Victor Moroz Jul 04 '16 at 02:26