title: How does Scala's mutable Map update [map(key) = newValue] syntax work?
body: <p>I'm working through Cay Horstmann's Scala for the Impatient book where I came across this way of updating a mutable map. </p>
  
  <pre><code>scala&gt; val scores = scala.collection.mutable.Map("Alice" -&gt; 10, "Bob" -&gt; 3, "Cindy" -&gt; 8)
  scores: scala.collection.mutable.Map[String,Int] = Map(Bob -&gt; 3, Alice -&gt; 10, Cindy -&gt; 8)
  
  scala&gt; scores("Alice") // retrieve the value of type Int
  res2: Int = 10
  
  scala&gt; scores("Alice") = 5 // Update the Alice value to 5
  
  scala&gt; scores("Alice")
  res4: Int = 5
  </code></pre>
  
  <p>It looks like <code>scores("Alice")</code> hits <code>apply</code> in <code>MapLike.scala</code>. But this only returns the value, not something that can be updated.</p>
  
  <p>Out of curiosity I tried the same syntax on an immutable map and was presented with the following error,</p>
  
  <pre><code>scala&gt; val immutableScores = Map("Alice" -&gt; 10, "Bob" -&gt; 3, "Cindy" -&gt; 8)
  immutableScores: scala.collection.immutable.Map[String,Int] = Map(Alice -&gt; 10, Bob -&gt; 3, Cindy -&gt; 8)
  
  scala&gt; immutableScores("Alice") = 5
  &lt;console&gt;:9: error: value update is not a member of scala.collection.immutable.Map[String,Int]
                immutableScores("Alice") = 5
            ^
  </code></pre>
  
  <p>Based on that, I'm assuming that <code>scores("Alice") = 5</code> is transformed into <code>scores update ("Alice", 5)</code> but I have no idea how it works, or how it is even possible.</p>
  
  <p>How does it work?</p>