Update multiple elements of a Clojure atom within a single swap statement? -
i have atom has 2 parts it.
(def thing (atom {:queue '() :map {}})) i want update both :queue , :map in 1 atomic stroke, prevent them getting off-sync.
queue individually:
(swap! thing update-in [:queue] (list 1)) (from question: how append nested list in clojure atom?)
map individually:
(swap! thing assoc-in [:map 1] (:key :value)) (from question: using swap merge (append to) nested map in clojure atom?)
how can these both within single swap statement? (assuming prevent them getting off-sync?)
you have 1 change want make, right? , write change pure function? need write function, , pass argument swap!.
(defn take-from-queue [{q :queue, m :map}] {:queue (rest q), :map m (assoc m :new-task (first q))}) (swap! thing take-from-queue) where of course have no idea want body of function do, i've made doesn't throw exception.
Comments
Post a Comment