reimplement walker in terms of recursive-path to support NONE removal
This commit is contained in:
parent
e8f15c4137
commit
340d6d3065
2 changed files with 13 additions and 12 deletions
|
|
@ -10,7 +10,8 @@
|
||||||
defdynamicnav
|
defdynamicnav
|
||||||
dynamicnav
|
dynamicnav
|
||||||
richnav
|
richnav
|
||||||
defrichnav]]
|
defrichnav
|
||||||
|
recursive-path]]
|
||||||
|
|
||||||
[com.rpl.specter.util-macros :refer
|
[com.rpl.specter.util-macros :refer
|
||||||
[doseqres]]))
|
[doseqres]]))
|
||||||
|
|
@ -826,16 +827,6 @@
|
||||||
(merge (reduce dissoc structure m-keys)
|
(merge (reduce dissoc structure m-keys)
|
||||||
newmap))))
|
newmap))))
|
||||||
|
|
||||||
(defnav
|
|
||||||
^{:doc "Using clojure.walk, navigate the data structure until reaching
|
|
||||||
a value for which `afn` returns truthy."}
|
|
||||||
walker
|
|
||||||
[afn]
|
|
||||||
(select* [this structure next-fn]
|
|
||||||
(i/walk-select afn next-fn structure))
|
|
||||||
(transform* [this structure next-fn]
|
|
||||||
(i/walk-until afn next-fn structure)))
|
|
||||||
|
|
||||||
(defnav
|
(defnav
|
||||||
^{:doc "Like `walker` but maintains metadata of any forms traversed."}
|
^{:doc "Like `walker` but maintains metadata of any forms traversed."}
|
||||||
codewalker
|
codewalker
|
||||||
|
|
@ -1285,3 +1276,13 @@
|
||||||
to implement post-order traversal."
|
to implement post-order traversal."
|
||||||
[& path]
|
[& path]
|
||||||
(multi-path path STAY))
|
(multi-path path STAY))
|
||||||
|
|
||||||
|
(def
|
||||||
|
^{:doc "Navigate the data structure until reaching
|
||||||
|
a value for which `afn` returns truthy. Has
|
||||||
|
same semantics as clojure.walk."}
|
||||||
|
walker
|
||||||
|
(recursive-path [apred] p
|
||||||
|
(cond-path (pred apred) STAY
|
||||||
|
coll? [ALL p]
|
||||||
|
)))
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@
|
||||||
(all-transform [structure next-fn]
|
(all-transform [structure next-fn]
|
||||||
(non-transient-map-all-transform structure next-fn (empty structure)))
|
(non-transient-map-all-transform structure next-fn (empty structure)))
|
||||||
|
|
||||||
clojure.lang.IRecord
|
#?(:clj clojure.lang.IRecord :cljs cljs.core/IRecord)
|
||||||
(all-transform [structure next-fn]
|
(all-transform [structure next-fn]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [res kv] (conj res (next-fn kv)))
|
(fn [res kv] (conj res (next-fn kv)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue