Filtering a map with a complex nested structure

What would be the best way to condition the nested fields of a complex nested structure, for example ...

{ :aa {:a "a_val",:b "b_val"}, :qq {:abc { :x1 {:x "abc",:u "ee"}, :x2 {:y "abc",:i "ee"}, :x3 {:x "abc",:i "ee"} } }, :ww {:xyz { :y1 {:x "abc",:u "ee"}, :y2 {:y "abc",:i "0"}, :y3 {:x "abc",:i "ee"} } } } 

I want to check if the "i" part exists and has the value "0" in each of aa, qq and ww and, depending on this, exclude (or perform any operation) on aa, qq and ww. For example, if "ww" has "i" = "0" in this position, then get a card as shown below

 { :ww {:xyz { :y1 {:x "abc",:u "ee"}, :y2 {:y "abc",:i "0"}, :y3 {:x "abc",:i "ee"} } } } 
+6
source share
1 answer
 user> (defn vvals [m] (when (map? m) (vals m))) 'user/vvals user> (filter #(some #{"0"} (for [v (vvals (val %)), v (vvals v)] (:iv))) xx) ([:ww {:xyz {:y3 {:x "abc", :i "ee"}, :y2 {:y "abc", :i "0"}, :y1 {:x "abc", :u "ee"}}}]) 
+3
source

Source: https://habr.com/ru/post/913052/


All Articles