This is really a followup to question Update hierarchical / tree structure in Clojure
I need to be able to change an Atom containing a map with lists of submaps. I would like to use fx assoc-in to do this, but i'm not sure how best to optain the path to the element i wich to change
My data structure:
(def x (atom {:name "A"
:id 1
:children [{:name "B"
:id 2
:children []}
{:name "C"
:id 3
:children [{:name "D"
:id 4
:children []}]}]}))
How do i make a function to find the path go a given id, fx give me path to map which contain #(= (:id %) 3):
(find-path 3 @x) ; => [0 :children 1]
So i can do this to get a new map:
(assoc-in @x [(conj (find-path...) :name)] "Jim")
Or update the Atom like this:
(swap! x assoc-in [(conj (find-path...) :name)] "Bob")