There's a fundamental issue here is that your update process is now a two steps process: find-path
and update-in
. However you are working with atoms so the path returned by find-path
may be incorrect by the time update-in
gets to see the value of the atom.
So you should combine them in a single fn so as to not have one deref
and one swap!
.
(defn update-by-id [x id f & args]
(apply update-in x (find-path x id) f args))
Now you can use a single swap!
:
(swap! x update-by-id 3 assoc :name "Bob")
However if you constantly update and access through ids you should also evaluate switching to another (flatter) representation for this piece of data.