Skip to content

Instantly share code, notes, and snippets.

@base698
Created March 11, 2016 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save base698/5643679b3a40d00cc35a to your computer and use it in GitHub Desktop.
Save base698/5643679b3a40d00cc35a to your computer and use it in GitHub Desktop.
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.

Given:

(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