This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-27
Channels
- # announcements (12)
- # babashka (18)
- # bangalore-clj (3)
- # beginners (110)
- # calva (14)
- # cestmeetup (4)
- # cider (4)
- # clj-kondo (2)
- # clojure (34)
- # clojure-colombia (5)
- # clojure-europe (11)
- # clojure-nl (8)
- # clojure-spec (19)
- # clojure-uk (11)
- # clojurescript (16)
- # clojureverse-ops (8)
- # community-development (4)
- # conjure (65)
- # core-async (19)
- # cursive (22)
- # data-science (7)
- # datascript (1)
- # datomic (20)
- # devcards (1)
- # figwheel-main (64)
- # fulcro (10)
- # graalvm (3)
- # helix (3)
- # kaocha (22)
- # malli (68)
- # meander (6)
- # off-topic (39)
- # pathom (6)
- # pedestal (2)
- # reagent (5)
- # remote-jobs (2)
- # reveal (30)
- # rum (4)
- # shadow-cljs (83)
- # specter (3)
- # tools-deps (9)
- # xtdb (18)
Hi. I am trying to collect all values which are associated to a keyword :tags
in a hierarchy of maps. Is there an easy way to do that using Specter?
I tried this, but it does not walk into maps which have :tags
:
(s/select [(s/walker #(and (map? %) (contains? % :tags))) :tags s/ALL]
{:a {:tags [1 {:tags [2]}]}
:b {:tags [3]}})
; => [1 {:tags [2]} 3]
@vincent.cantin easy to do with recursive-path
user=> (def data
#_=> {:a {:tags [1 {:tags [2]}]}
#_=> :b {:tags [3]}})
#'user/data
user=>
user=> (def MY-WALKER
#_=> (recursive-path [] p
#_=> (continue-then-stay
#_=> (cond-path map? MAP-VALS
#_=> sequential? ALL)
#_=> p
#_=> )))
#'user/MY-WALKER
user=>
user=> (select [MY-WALKER map? (must :tags) ALL] data)
[2 1 {:tags [2]} 3]