Search code examples
clojure

Changing nested element of an atom


I am trying to change value of an atom:

#atom[{{:other-site-conf 2499/2500, :own-unconf|other-conf [[30.752499999999998 1.0126843266559153 12] "Humidity"], :other-site-unconf 1/2500, :both-unconf [[27.563987107797804 4.984857204039122 7511] "Humidity"], :site-id 1, :other-site-quant 0.86235090749618} {:other-site-conf 2497/2500, :own-unconf|other-conf [[22.976875 0.09445843442135488 4] "Temperature"], :other-site-unconf 3/2500, :both-unconf [[20.920551354838697 1.0618445458730512 7511] "Temperature"], :site-id 0, :other-site-quant 0.7673990631272951}} 0x5bf8ef86]

In this I want to change map values inside :both-unconf of second map that is of :site-id 0

I have tried using:

(swap! prob-cond update-in [1 1 :both-unconf 1 1 0] 22)

but not working.


Solution

  • You need to pass swap! a function.
    (swap! prob-cond #(update-in % [1 1 :both-unconf 1 1 0] (constantly 22))