This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-21
Channels
- # announcements (3)
- # babashka (98)
- # beginners (69)
- # chlorine-clover (6)
- # cider (24)
- # cljsrn (2)
- # clojure (97)
- # clojure-australia (2)
- # clojure-berlin (6)
- # clojure-dev (57)
- # clojure-dusseldorf (4)
- # clojure-europe (19)
- # clojure-italy (5)
- # clojure-nl (10)
- # clojure-seattle (1)
- # clojure-uk (44)
- # clojuredesign-podcast (13)
- # clojurescript (45)
- # cursive (4)
- # data-science (1)
- # datomic (32)
- # emacs (7)
- # events (5)
- # fulcro (17)
- # java (12)
- # jobs (1)
- # lumo (2)
- # malli (5)
- # observability (16)
- # off-topic (1)
- # pathom (3)
- # pedestal (4)
- # rdf (14)
- # re-frame (54)
- # reagent (4)
- # releases (3)
- # remote-jobs (1)
- # reveal (55)
- # shadow-cljs (34)
- # spacemacs (14)
- # specter (9)
- # tools-deps (16)
- # xtdb (7)
Hi everyone,
if i have a tree of nested lists with all keyword data type, what is the efficient pattern to select all sublists that start with specific keyword ?
(:a
(:x
(:x :xoo)
(:y (:ya :yay))
(:z (:t :till)
(:y (:v :hello) (:h :world)))))
need to select all lists that starts with :y
output
(:y (:ya :yay))
(:y (:v :hello) (:h :world))
(def LISTS
(recursive-path [] p
(if-path list?
(stay-then-continue ALL p)
STOP)))
user=> (select [LISTS (selected? FIRST (pred= :y))] your-list)
[(:y (:ya :yay)) (:y (:v :hello) (:h :world))])
👍 3
or use walker
(select [(walker (fn [x]
(and (list? x)
(= (first x) :y))))]
'(:a
(:x
(:x :xoo)
(:y (:ya :yay))
(:z (:t :till)
(:y (:v :hello) (:h :world))))))
;; => [(:y (:ya :yay)) (:y (:v :hello) (:h :world))]
👍 3
i have used tree-seq and filter based on some conditions and it's working, but it's worth to try those approaches too