title: Scala update value in a map while iterating
body: <p>I'm trying to update the value in a map[String, WordCount] while iterating this</p>
  
  <pre><code>case class WordCount(name: String,
                   id: Int,
                   var count: Double,
                   var links: scala.collection.mutable.HashMap[String, Double],
                   var ent: Double) {
  
      def withEnt(v: Double): WordCount = {println(s"v: $v"); copy(ent = v)}
  }
  
  var targets = mutable.HashMap[String, WordCount]()
  </code></pre>
  
  <p>The function calEnt is:</p>
  
  <pre><code>def calEnt(total: Double, links: scala.collection.mutable.HashMap[String, Double]): Double = {
      var p: Double = 0.0
      var ent: Double = 0.0
      links.map(d =&gt; {
        p = d._2 / total
        ent -= p * Math.log(p)
      })
      return ent
    }
  </code></pre>
  
  <p>And I'm using:</p>
  
  <pre><code>targets.map(m =&gt; m._2.withEnt(calEnt(m._2.count, m._2.links)))
  </code></pre>
  
  <p>for iterating the map and calculate the new value for <code>ent</code> and update this with <code>withEnt</code>. I can imprime in console the new value but it is not setting inside the map. What is the way to do that? please.</p>