I want to merge large maps in Scala
This a question that has been asked before, but none of the answers seemed efficient. All of the idiomatic solutions seemed to have quadratic cost, and allocate lots of memory
Scala: Merge maps by key Improvements for a Map merge function
Here's the basic problem:
Given
val x: Map[A,B] = ...
val y: Map[A,C] = ...
def f(Option[B],Option[C]): D = ...
Generate
val z: Map[A,D]
So I want to merge x and y and produce a map z with a union of all the keys. The values are calculated combining the values of x and y.
Is there an idiomatic way to do this that is both functional and efficient for very large maps? Has something been added to Scala 10 or 11 (or coming in 12)?
Thank you Peter