Srini
Srini

Reputation: 883

Get key-value from Mutable Map in Clojure

I have created mutable state map using an atom. I would like to get the value of the key from the map. I have tried it in the below way, But it returns "nil" value

(def coll1 (atom {}) )
(swap! coll1 assoc :a "XXXX" :b "XXXXXX")

This statement printing

(println coll1)

#object[clojure.lang.Atom 0x771a660 {:status :ready, :val {:a XXXX, :b XXXXXX}}]

I have written this statement to fetch value of :a

(println (get-in coll1 [:val :a]))

Upvotes: 1

Views: 390

Answers (1)

JobSam
JobSam

Reputation: 317

You need to dereference the atom. This link will help. For your case, you are looking for something like (get @coll1 :a) or (:a @coll1) or (@coll1 :a)

Upvotes: 3

Related Questions