title: Scala immutable map, when to go mutable?
body: <p>My present use case is pretty trivial, either mutable or immutable Map will do the trick. </p>
  
  <p>Have a method that takes an immutable Map, which then calls a 3rd party API method that takes an immutable Map as well</p>
  
  <pre><code>def doFoo(foo: String = "default", params: Map[String, Any] = Map()) {
  
    val newMap = 
      if(someCondition) params + ("foo" -&gt; foo) else params
  
    api.doSomething(newMap)
  }
  </code></pre>
  
  <p>The Map in question will generally be quite small, at most there might be an embedded List of case class instances, a few thousand entries max. So, again, assume little impact in going immutable in this case (i.e. having essentially 2 instances of the Map via the newMap val copy).</p>
  
  <p>Still, it nags me a bit, copying the map just to get a new map with a few k->v entries tacked onto it.</p>
  
  <p>I could go mutable and <code>params.put("bar", bar)</code>, etc. for the entries I want to tack on, and then <code>params.toMap</code> to convert to immutable for the api call, that is an option. but then I have to import and pass around mutable maps, which is a bit of hassle compared to going with Scala's default immutable Map.</p>
  
  <p>So, what are the general guidelines for when it is justified/good practice to use mutable Map over immutable Maps?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong>
  so, it appears that an add operation on an immutable map takes near constant time, confirming @dhg's and @Nicolas's assertion that a full copy is not made, which solves the problem for the concrete case presented.</p>