title: putIfAbsent for immutable maps?
body: <p>I often find myself writing code like this:</p>
  
  <pre><code>import scala.collection.immutable._
  
  var foos = Map.empty[Int, Foo]
  
  def fooOf(n: Int): Foo = {
    foos.get(n) match {
      case Some(foo) =&gt; foo
      case None =&gt;
        val foo = new Foo(n)
        foos = foos.updated(n, foo)
        foo
    }
  }
  </code></pre>
  
  <p>With a concurrent map, the code looks much nicer:</p>
  
  <pre><code>import scala.collection.concurrent._
  
  var foos = TrieMap.empty[Int, Foo]
  
  def fooOf(n: Int): Foo = {
    val foo = new Foo(n)
    foos.putIfAbsent(n, foo) getOrElse foo
  }
  </code></pre>
  
  <p>But I really want a non-concurrent, immutable map. Is there something like <code>putIfAbsent</code> for it?</p>
  
  <p>(By the way, in the concurrent example, is it possible to create the <code>Foo</code> only if it is indeed absent?)</p>