Filter a map with complex nested structure
clojure
Solution
user> (defn vvals [m] (when (map? m) (vals m)))
'user/vvals
user> (filter #(some #{"0"} (for [v (vvals (val %)), v (vvals v)] (:i v))) xx)
([:ww {:xyz {:y3 {:x "abc", :i "ee"}, :y2 {:y "abc", :i "0"}, :y1 {:x "abc", :u "ee"}}}])
Problem
What would be a best way to impose a condition on the nested fields of complex nested structure like... ``` { :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 whether the "i" part exist and has value "0" in each of aa,qq and ww and depending upon that exclude(or perform any operation) on aa,qq and ww. For example if "ww" has "i"="0" at that position then get a map like below ``` { :ww {:xyz { :y1 {:x "abc",:u "ee"}, :y2 {:y "abc",:i "0"}, :y3 {:x "abc",:i "ee"} } } } ```