开发者

How do I extract values from each of the values in a map of maps?

开发者 https://www.devze.com 2023-03-17 13:30 出处:网络
I\'ve just started learning Clojure, if I define the following map: (def distributions {:normal {:title \"Normal\" :mean 0 :sd 1}

I've 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 :shap开发者_JAVA百科e 1}})

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


(defn get-titles [] (map :title (vals distributions)))


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

0

精彩评论

暂无评论...
验证码 换一张
取 消