Shile
Shile

Reputation: 1063

Getting values from nested maps

I have a nested map,how can i get values of all :kvota keywords?the result should be - 5.8,3.2,2.25.I tried using select-keys but without any luck...

{: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}}}}

Upvotes: 2

Views: 162

Answers (1)

overthink
overthink

Reputation: 24463

This will get the values corresponding to each :kvota anywhere in the data structure.

;; 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)

Upvotes: 4

Related Questions