This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-31
Channels
- # aws (1)
- # beginners (70)
- # boot (12)
- # calva (45)
- # cider (45)
- # clara (1)
- # cljdoc (10)
- # cljs-dev (133)
- # clojure (315)
- # clojure-dev (2)
- # clojure-europe (2)
- # clojure-italy (16)
- # clojure-nl (1)
- # clojure-spec (23)
- # clojure-uk (19)
- # clojurescript (48)
- # cursive (11)
- # data-science (5)
- # datomic (18)
- # figwheel-main (3)
- # fulcro (18)
- # graphql (14)
- # jackdaw (1)
- # juxt (1)
- # kaocha (1)
- # off-topic (10)
- # other-languages (3)
- # pathom (2)
- # pedestal (7)
- # re-frame (23)
- # reagent (1)
- # reitit (4)
- # ring-swagger (12)
- # rum (4)
- # shadow-cljs (26)
- # specter (6)
- # speculative (12)
- # tools-deps (44)
- # vim (8)
- # yada (2)
I’m having trouble with a recursive requirement. Here’s the example:
(->> {:gender :male
:type :person
:name "Luke"
:mother {:gender :female
:type :person
:name "Padme"}
:friends [{:gender :male
:type :person
:name "Han"}
{:gender :male
:type :person
:name "Chewbacca"}]
:mentors {:type :group
:people [{:gender :male
:type :person
:name "Obiwan"}
{:gender :male
:type :person
:name "Yoda"}]}}
(select [(recursive-path [] p
(if-path (fn [v] (and (map? v) (:gender v)))
(continue-then-stay (multi-path [(must :friends) ALL]
[MAP-VALS #(:gender %)])
p)))]))
=>
[{:gender :male, :type :person, :name "Han"}
{:gender :male, :type :person, :name "Chewbacca"}
{:gender :female, :type :person, :name "Padme"}
{:gender :male,
:type :person,
:name "Luke",
:mother {:gender :female, :type :person, :name "Padme"},
:friends [{:gender :male, :type :person, :name "Han"} {:gender :male, :type :person, :name "Chewbacca"}],
:mentors {:type :group,
:people [{:gender :male, :type :person, :name "Obiwan"} {:gender :male, :type :person, :name "Yoda"}]}}]
How can I get it to also return the mentors? They are :persons as wellmulti-path only seems to support 2 variations. I guess another way of asking this is how can I combine the selections of 3 paths into 1?
One way would be to use a clojure.walk to extract all :person maps and wrap that in a specter nav (maybe view). I can’t use specter/walker because it stops on matches in each branch so it would only return 1 mentor. ideally I’d like some specter native nav composition but can’t see how.
@steveb8n I think you're looking for:
(def PEOPLE
(recursive-path [] p
(continue-then-stay
(multi-path
(must :mother)
(must :father)
[(must :friends) ALL]
[(must :mentors) :people ALL]
)
p
)))
🙏 5