This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-24
Channels
- # arachne (3)
- # beginners (39)
- # boot (3)
- # cider (91)
- # cljs-dev (56)
- # cljsrn (4)
- # clojure (267)
- # clojure-dusseldorf (1)
- # clojure-estonia (1)
- # clojure-greece (2)
- # clojure-italy (6)
- # clojure-nl (2)
- # clojure-russia (18)
- # clojure-spec (27)
- # clojure-uk (136)
- # clojurescript (19)
- # core-async (2)
- # cursive (6)
- # datomic (17)
- # emacs (2)
- # fulcro (86)
- # graphql (4)
- # hoplon (13)
- # jobs-discuss (7)
- # jobs-rus (1)
- # keechma (34)
- # keyboards (7)
- # leiningen (5)
- # luminus (4)
- # lumo (8)
- # off-topic (13)
- # om (6)
- # onyx (26)
- # re-frame (22)
- # reagent (1)
- # reitit (2)
- # remote-jobs (8)
- # ring (3)
- # ring-swagger (5)
- # rum (8)
- # shadow-cljs (45)
- # specter (6)
- # unrepl (16)
- # yada (15)
Given add-ref
and parse-tree
in the following snippet, is there a way to combine this pair of transform/traverse into a single traversal (to improve performance by not requiring a multi-pass of a large datastructure?)
(def NODE
(sp/recursive-path [] p
(sp/continue-then-stay
(sp/must :children)
sp/MAP-VALS
p)))
(def terminal2
(sp/richnav [afn]
(sp/select* [this vals structure next-fn]
(throw (Exception. "'terminal2' should only be used in multi-transform")))
(sp/transform* [this vals structure next-fn]
(afn vals structure))))
(def nodes-with-refs
(sp/recursive-path [] p
(sp/continue-then-stay
(sp/putval :children)
(sp/must :children)
sp/ALL
(sp/collect-one sp/FIRST)
sp/LAST
p)))
(defn add-ref [root]
(sp/multi-transform
[(sp/putval :root)
:root
nodes-with-refs
:ref
(terminal2 (fn [vals _] (ref/unparse vals)))]
root))
(defn parse-tree [root]
(reduce
(fn [result item]
(if-let [parsed (parse-node item)]
(conj result parsed)
result))
[]
(sp/traverse [:root :children MAP-VALS NODE] root)))
(->> test-segment ;; potentially large datastructure with form {:root {:name "root" .. :children {..}}}
add-ref ;; add path down the tree to each node in the tree, e.g., "/a/b/c" where A, B, C are nodes with names a, b, c
parse-tree)
@dadair can you just collect the path in parse-tree
?
besides that, the latest release adds vtransform
which eliminate the need for you to do multi-transform
with custom terminal2
you might benefit here from a new vselect
which navigates to [collected-vals navigated-value]