Reputation: 26171
I'm trying to do a simple aggregation in a collection I've grouped. Like this:
case class Foo(key:String, value:Int)
val minPerKey = lotsOfFoos.groupBy(_.key).mapValues(_.minBy(_.value))
Now I want to do the same in parallel but ParMap doesn't have a mapValues function.
Why is this so, and how should I do it alternatively?
Upvotes: 1
Views: 222
Reputation: 386
Scala 2.10 has mapValues for ParMap.
But there isn't a whole lot of benefit to using mapValues with a ParMap. The mapValues method just gives you a new Map that applies your function when reading values, it doesn't actually change the values in the Map. So you would need to do some other action that would force the creation of a new Map with the mapped values.
Upvotes: 3
Reputation: 26171
Since mapValues is not present on ParMapLike, there are two options left:
.map{case (key, value) => (key->value.minBy(_.value)) }
.toMap.mapValues(_.minBy(_.value))
I don't know why mapValues isn't just implemented on ParMapLike
Upvotes: 1