This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-22
Channels
- # beginners (114)
- # boot (10)
- # cljs-dev (18)
- # clojure (57)
- # clojure-russia (12)
- # clojure-spec (2)
- # clojure-uk (1)
- # clojurescript (62)
- # cursive (49)
- # datomic (3)
- # emacs (2)
- # mount (1)
- # off-topic (25)
- # onyx (58)
- # pedestal (5)
- # re-frame (5)
- # ring-swagger (1)
- # specter (8)
- # unrepl (2)
- # untangled (4)
- # vim (10)
- # yada (39)
anyone have a way to get the ancestors of a node in a tree, with or without specter.zipper?
closest I can get is collecting the path with
clojure
(def NodeAndParents
(s/recursive-path [id] p
(s/if-path #(= (:id %) id)
s/STAY
(s/if-path #(empty? (:children %))
[s/DISPENSE s/STOP]
[(s/collect-one :id) :children s/ALL p]))))
then using the collected ids to go through the tree again, selecting the nodes whose id is in that set@jeremyraines yea that's pretty much how you do it with specter
ah ok, cool, thanks
you can change the last part to (if-path [:children ALL] [(collect-one :id) :children ALL p])
calling DISPENSE
before STOP
doesn't do anything
and if-path
has default "else" branch of STOP