title: Scala: how to merge a collection of Maps
body: <p>I have a List of Map[String, Double], and I'd like to merge their contents into a single Map[String, Double].  How should I do this in an idiomatic way?  I imagine that I should be able to do this with a fold.  Something like:</p>
  
  <pre><code>val newMap = Map[String, Double]() /: listOfMaps { (accumulator, m) =&gt; ... }
  </code></pre>
  
  <p>Furthermore, I'd like to handle key collisions in a generic way.  That is, if I add a key to the map that already exists, I should be able to specify a function that returns a Double (in this case) and takes the existing value for that key, plus the value I'm trying to add.  If the key does not yet exist in the map, then just add it and its value unaltered.</p>
  
  <p>In my specific case I'd like to build a single Map[String, Double] such that if the map already contains a key, then the Double will be added to the existing map value.</p>
  
  <p>I'm working with mutable maps in my specific code, but I'm interested in more generic solutions, if possible.</p>