title: Groovy modify map elements while iterating a map
body: <p>I need to modify map elements while iterating a map, in my case subtract some elements (list). Like this:</p>
  
  <pre><code>def a = [
     1: [1, 2, 3],
     2: [3, 2, 4],
     3: [3, 2, 4],
     4: [5, 2, 1],
  ]
  def b = [3]
  println a
  a.values().each{ tr -&gt;
     tr = tr - b
  }
  println a
  </code></pre>
  
  <p>The <code>a</code> map has not changed. Result is:</p>
  
  <pre><code>[1:[1, 2, 3], 2:[3, 2, 4], 3:[5, 3, 1], 4:[5, 2, 1]]
  [1:[1, 2, 3], 2:[3, 2, 4], 3:[5, 3, 1], 4:[5, 2, 1]]
  </code></pre>
  
  <p>However, I want the result to be <code>[1:[1, 2], 2:[2, 4], 3:[5, 1], 4:[5, 2, 1]]</code>. What I am doing wrong? Due to the fact that the initial map is rather big I do not want to construct another map with less elements (result map).</p>