If I have this:
val a = Array(...)
and I write
a.par.map(e => someFunc(e))
Will the resulting collection be in the same order as the non-parallel collection?
If I have this:
val a = Array(...)
and I write
a.par.map(e => someFunc(e))
Will the resulting collection be in the same order as the non-parallel collection?
Yes, but the function itself is executed without any particular order.
The parallel collections maintain all of the contracts of their non-parallel equivalents.
On collections in which a
map
operation preserves order, such asList
, order will be preserved by the parallelmap
as well. On collections in whichmap
does not preserve order, such asSet
, order will not be preserved in the parallel version.With unordered collections, there is no guarantee that the result of a parallel operation will even have the same traversal order as its non-parallel equivalent.