Question

According to the paper on parallel collections and searching on the internet, parallel collections are supposed to work with views, but I am not clear on the difference between

coll.par.view.someChainedIterations

and

coll.view.par.someChainedIterations

It seems like coll.view.par looses the viewness of the collection:

scala> val coll = 1 to 3
coll: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3)

scala> coll.view.par
res2: scala.collection.parallel.ParSeq[Int] = ParArray(1, 2, 3)

scala> coll.par.view
res3: java.lang.Object with scala.collection.parallel.ParSeqView[Int,scala.collection.parallel.immutable.ParSeq[Int],scala.collection.immutable.Seq[Int]] = $anon$1(1, 2, 3)

but I do not know why. Is it a feature or a bug?

Was it helpful?

Solution

This is probably an oversight, and should be fixed.

The par on sequential views could be implemented by calling the par on the underlying collection, which would result in a chain of recursive par calls until the underlying is a strict collection that the view was originally obtained from. If this collection can be turned into its corresponding parallel collection efficiently, than the newly obtained parallel view can be constructed efficiently (see here).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top