What's that i+=1
for?
Otherwise, you are looking for (using Ints for a simple example):
scala> val m = Map(1 -> 2, 2 -> 3)
m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 2 -> 3)
scala> val mp = m.toParArray map {case(a,b) => (a,b+1)}
mp: scala.collection.parallel.mutable.ParArray[(Int, Int)] = ParArray((1,3), (2,4))
scala> mp.toArray
res17: Array[(Int, Int)] = Array((1,3), (2,4))
You can just replace b+1
by someFunc(b)
.
someFunc
will be executed in parallel because we use a parallel collection (m.toParArray
), and at the end we use .toArray
to convert our parArray to a sequential one (not sure you need that).