开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜