2

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

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Excellent answer! I would've never thought to use tree-seq that way. By the way, (remove nil? (map f ...)) is the same as (keep f ...).
@OmriBernstein keep - great idea. I've made the change. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.