Dynamically update map
<p>I have some code like this:</p>

<pre><code>$set($map = {"a": [1,1], "b", [2,2] } )

#foreach( $key in $map.keySet() )
  #set($val = $map.get($key).toList())
  #set($junk = $val.add(9))
  #set($junk = $map.put($val)
#end
</code></pre>

<p>At the end, I want <code>$map</code> to contain</p>

<pre><code>{"a": [1,1,9], "b", [2,2,9] }
</code></pre>

<p>but because the <code>put()</code> reuses the same varible, the arrays are passed by reference, and <code>$map</code> ends up as:</p>

<pre><code>{"a": [2,2,9], "b", [2,2,9] }
</code></pre>

<p><strong>update</strong></p>

<p>I think it should be possible with something like this but I suspect I need to escape the <code>$</code> in the variable names.</p>

<pre><code>#evaluate( "$map.get($key).asList().add(9)" )
</code></pre>

<p><strong>Update 2</strong></p>

<p>I ended up changing the way my data was structured so that I didn't have arrays inside maps/sets. I didn't find a way to update them inside the set.</p>