Last Updated: February 25, 2016
· runexec

Map Values 2

I would like to add more detail on maps that wasn't covered in "Getting values from maps"[]=leiningen&t[]=clojure

;; Get the value or the value is "Not Found"
user=> (get {:a 1 :b 2} :first-name "Not found") "Not found"
;; Trying again with :a
user=> (get {:a 1 :b 2} :a "Not found") 1
;; This specific map can act as a function in Clojure
user=> ({:a 1 :b 2} :a) 1
;; So can this keyword
user=> (:a {:a 1 :b 2}) 1
;; Failed to find nested values
user=> (:c {:a {:b {:c "Found"}}}) nil
;; Nested value found
user=> (get-in {:a {:b {:c "Found"}}} [:a :b :c]) "Found"
;; Same
user=> (-> {:a {:b {:c "Found"}}} :a :b :c) "Found"