Can someone help me with the parallel collections library?
If m
is of type ParSeq[A]
and f
is of type List[A]=>B
, then I get an confusing error on the expression m.toList.grouped(2).toSeq.par.map(f)
. Somehow it thinks I’m calculated a collection, and I need to explicitly calculate an immutable collection? This is somewhat surprising for several reasons. Isn’t the default type immutable anyway? It seems I should have to do something special to get a mutable collection.
Q1: Aren’t immutable collections supposed to be the default?
I know that’s a vague question, but it seems like the intended intuition. Right?
Error:(39, 63) type mismatch;
found : ParSeq[B] (in scala.collection.parallel)
required: ParSeq[B] (in scala.collection.parallel.immutable)
val reduced:ParSeq[B] = m.toList.grouped(2).toSeq.par.map { b =>
Here is a MWE of the code.
The second reason why this is confusing is that if it try the same code in 2.13, it get completely different errors. Q2: Should we not be using the parallel collections library anymore?
object parallel is not a member of package collection
Q3: What is the correct way to calculate a ParSeq[B]
in scala.collection.parallel.immutable
, rather than a ParSeq[B]
in scala.collection.parallel
?