How to extract values โ€‹โ€‹from each of the values โ€‹โ€‹in a map map?

I just started learning Clojure if I define the following map:

(def distributions {:normal {:title "Normal" :mean 0 :sd 1} :beta {:title "Beta" :a 1 :b 3} :gamma {:title "Gamma" :rate 1/2 :shape 1}}) 

how do I write (defn get-titles [] ...) function that returns ("Normal", "Beta", "Gamma") ?

+8
clojure
source share
2 answers
 (defn get-titles [] (map :title (vals distributions))) 
+11
source share

Alternatively: (for [[kv] distr] (:title v))

+5
source share

All Articles