从嵌套映射中获取值

时间:2013-11-21 02:20:16

标签: clojure

我有一个嵌套的地图,我怎么能得到所有的值:kvota关键字?结果应该是 - 5.8,3.2,2.25。我尝试使用select-keys但没有任何运气......

{:b4f0d011-31a2-4be3-bb8d-037725310207 {:tiket {:3 {:id 13, :par Porto - Zenit, :igra 2, :kvota 5.8}, :2 {:id 12, :par Celtic - Ajax, :igra x, :kvota 3.2}, :1 {:id 11, :par Arsenal - Dortmund, :igra 1, :kvota 2.25}}}}

1 个答案:

答案 0 :(得分:3)

这将获得与数据结构中任何位置的每个:kvota对应的值。

;; Data in quesiton doesn't read as-is, so this is altered slightly.
(def data
  {:b4f0d011-31a2-4be3-bb8d-037725310207
   {:tiket
    {:1 {:kvota 2.25, :par "Arsenal - Dortmund", :igra 1, :id 11}
     :3 {:kvota 5.8, :par "Porto - Zenit", :igra 2, :id 13}
     :2 {:kvota 3.2, :par "Celtic - Ajax", :igra "x", :id 12}}}})

(keep :kvota (tree-seq map? vals data)) ; (2.25 5.8 3.2)