title: Clojure idiomatic way to update multiple values of map
body: <p>This is probably straightforward, but I just can't get over it.
  I have a data structure that is a nested map, like this:</p>
  
  <pre><code>(def m {:1 {:1 2 :2 5 :3 10} :2 {:1 2 :2 50 :3 25} :3 {:1 42 :2 23 :3 4}})
  </code></pre>
  
  <p>I need to set every <code>m[i][i]=0</code>. This is simple in non-functional languages, but I cant make it work on Clojure. How is the idiomatic way to do so, considering that I do have a vector with every possible value? (let's call it <code>v</code>)</p>
  
  <p>doing <code>(map #(def m (assoc-in m [% %] 0)) v)</code> will work, but using <code>def</code> inside a function on <code>map</code> doesn't seems right.
  Making m into an atomic version and using <code>swap!</code> seems better. But not much It also seems to be REALLY slow.</p>
  
  <pre><code>(def am (atom m))
  (map #(swap! am assoc-in[% %] 0) v)
  </code></pre>
  
  <p>What is the best/right way to do that?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Some great answers over here. I've posted a follow-up question here <a href="https://stackoverflow.com/questions/32688146/clojure-iterate-over-map-of-sets">Clojure: iterate over map of sets</a> that is close-related, but no so much, to this one.</p>