Skip to content

Instantly share code, notes, and snippets.

@base698 base698/
Created Mar 11, 2016

What would you like to do?
update-in, get-in, and assoc-in

Not using these functions is doing it wrong.

I recently went back and looked at some clojure I wrote when I was learning.


(def x {:a 1 :b {:c 3}})

So for a case like this, where I wanted to increment {:c 3} and have the change persist in x I was doing code like this:

(let [val (:c (x :b))
      updated (inc val)]
      (set! x (assoc x :b (assoc (:b x) :c updated))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.