niloofar
niloofar

Reputation: 2334

Clojure update nested map inside atom

I have an atom like this, inside a let:

(let [scors (atom {:one   {:year-one [] :year-five [] :year-ten []}
                   :two   {:year-one [] :year-five [] :year-ten []}
                   :three {:year-one [] :year-five [] :year-ten []})]
    
some code...
)

Inside a for loop, I want to swap this atom to add data depends on the if statements inside that loop.

For example I tried this, but it didn't work:

(swap! scors :assoc {:one :year-one} (:set-of-inputs each)))

So for example I want to add {:name "someone"} to :one :year-one. How can I update the :year-one?

Thank you in advance.

Upvotes: 0

Views: 114

Answers (1)

erdos
erdos

Reputation: 3538

Use swap! with update-in

(swap! scors update-in [:one :year-one] conj (:set-of-inputs each))

Upvotes: 2

Related Questions