This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-05
Channels
- # announcements (23)
- # babashka (23)
- # beginners (48)
- # calva (41)
- # clj-kondo (41)
- # cljs-dev (75)
- # cljsrn (5)
- # clojure (85)
- # clojure-europe (46)
- # clojure-nl (2)
- # clojure-spec (70)
- # clojure-uk (4)
- # clojurescript (52)
- # core-async (2)
- # cursive (16)
- # datahike (2)
- # datomic (4)
- # emacs (15)
- # figwheel-main (2)
- # fulcro (5)
- # gratitude (5)
- # helix (14)
- # introduce-yourself (2)
- # jackdaw (13)
- # keyboards (2)
- # lsp (8)
- # luminus (5)
- # malli (3)
- # meander (12)
- # nextjournal (52)
- # off-topic (19)
- # other-languages (1)
- # overtone (3)
- # pathom (4)
- # podcasts-discuss (1)
- # re-frame (6)
- # reitit (1)
- # releases (2)
- # ring (3)
- # sci (22)
- # shadow-cljs (3)
- # specter (1)
- # testing (3)
- # tools-deps (100)
- # uncomplicate (2)
Can someone help explain to me how walker
works. Below I'm trying to exclude all maps and submaps that contain a value "red"
(defn has-red? [x]
(prn x)
(cond (map? x) (nil? ((-> x vals set) "red"))
:else false))
(let [j [{"a" 2
"b" 4
"d" "green"
"e" [{"z" "zzz"
"y" "yyy"}]
"c" {"d" 5
"e" "red"
"g" {"h" 9
"i" \a}}
"m" {"aa" 99}}
{"sdfsdf" "gsdgdfgdfg"
"fsf" 979
"d" "orange"
"e" [{"z" "red"
"y" "yyy"}
{"jfoj" "purple"
"fffj" 5}]
"c" {"d" 5
"e" "purple"
"g" {"h" 9
"i" \a}}
"m" {"red" 99}}]]
(select (walker has-red?) j))
If I change has-red?
to just return false
. I get an empty vector, this makes sense, it also prints every key and value in the structure. If I just return true, then it prints the whole structure once and returns that....
Can I walk each element, and only returns those that has-red
returns false for, that way dropping any sub maps that contain a value "red"
? What function should I be looking at ?