implement traverse-all

This commit is contained in:
nathanmarz 2017-02-12 09:38:56 -05:00
parent 80b3857b08
commit 62c998a472
2 changed files with 23 additions and 0 deletions

View file

@ -358,6 +358,11 @@
[apath structure]
`(i/do-compiled-traverse (path ~apath) ~structure))
(defmacro traverse-all
"Returns a transducer that traverses over each element with the given path."
[apath]
`(i/compiled-traverse-all* (path ~apath)))
(defmacro replace-in
"Similar to transform, except returns a pair of [transformed-structure sequence-of-user-ret].
The transform-fn in this case is expected to return [ret user-ret]. ret is
@ -512,6 +517,10 @@
[apath structure]
(compiled-traverse (i/comp-paths* apath) structure))
(def compiled-traverse-all i/compiled-traverse-all*)
(defn traverse-all* [apath] (compiled-traverse-all (i/comp-paths* apath)))
;; Transformation functions
(def ^{:doc "Version of transform that takes in a path precompiled with comp-paths"}

View file

@ -316,6 +316,20 @@
))))
(defn compiled-traverse-all* [path]
(fn [xf]
(fn
([] (xf))
([result] (xf result))
([result input]
(reduce
(fn [r i]
(xf r i))
result
(do-compiled-traverse path input)
)
))))
(defn compiled-select* [path structure]
(let [res (mutable-cell (transient []))
result-fn (fn [structure]