glvqka
Last Updated: February 25, 2016
·
1.866K
· runexec
81609937c20aeab3598aea56f1f4f022

Map Values 2

I would like to add more detail on maps that wasn't covered in "Getting values from maps" http://coderwall.com/p/x81mqg?i=2&p=1&q=sort%3Acreated_at+desc&t[]=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"

Say Thanks
Respond