reimplement codewalker so it works with NONE
This commit is contained in:
parent
340d6d3065
commit
d0ff9bbc35
2 changed files with 24 additions and 9 deletions
|
|
@ -3,6 +3,9 @@
|
||||||
* Added `pred=`, `pred<`, `pred>`, `pred<=`, `pred>=` for filtering using common comparisons
|
* Added `pred=`, `pred<`, `pred>`, `pred<=`, `pred>=` for filtering using common comparisons
|
||||||
* Add `map-key` navigator
|
* Add `map-key` navigator
|
||||||
* Add `set-elem` navigator
|
* Add `set-elem` navigator
|
||||||
|
* Add `ALL-WITH-META` navigator
|
||||||
|
* `walker` and `codewalker` can now be used with `NONE` to remove elements
|
||||||
|
* Extend `ALL` to work on records (navigate to key/value pairs)
|
||||||
* Workaround ClojureScript bug that emits warnings for vars named the same as a private var in cljs.core (in this case `NONE`, added as private var to cljs.core with 1.9.562)
|
* Workaround ClojureScript bug that emits warnings for vars named the same as a private var in cljs.core (in this case `NONE`, added as private var to cljs.core with 1.9.562)
|
||||||
* For ALL transforms on maps, interpret transformed key/value pair of size < 2 as removal
|
* For ALL transforms on maps, interpret transformed key/value pair of size < 2 as removal
|
||||||
* Bug fix: Fix incorrect inline compilation when a dynamic function invocation is nested in a data structure within a parameter to a navigator builder
|
* Bug fix: Fix incorrect inline compilation when a dynamic function invocation is nested in a data structure within a parameter to a navigator builder
|
||||||
|
|
|
||||||
|
|
@ -652,6 +652,19 @@
|
||||||
(transform* [this structure next-fn]
|
(transform* [this structure next-fn]
|
||||||
(n/all-transform structure next-fn)))
|
(n/all-transform structure next-fn)))
|
||||||
|
|
||||||
|
(defnav
|
||||||
|
^{:doc "Same as ALL, except maintains metadata on the structure."}
|
||||||
|
ALL-WITH-META
|
||||||
|
[]
|
||||||
|
(select* [this structure next-fn]
|
||||||
|
(n/all-select structure next-fn))
|
||||||
|
(transform* [this structure next-fn]
|
||||||
|
(let [m (meta structure)
|
||||||
|
res (n/all-transform structure next-fn)]
|
||||||
|
(if (some? res)
|
||||||
|
(with-meta res m)
|
||||||
|
))))
|
||||||
|
|
||||||
(defnav
|
(defnav
|
||||||
^{:doc "Navigate to each value of the map. This is more efficient than
|
^{:doc "Navigate to each value of the map. This is more efficient than
|
||||||
navigating via [ALL LAST]"}
|
navigating via [ALL LAST]"}
|
||||||
|
|
@ -827,15 +840,6 @@
|
||||||
(merge (reduce dissoc structure m-keys)
|
(merge (reduce dissoc structure m-keys)
|
||||||
newmap))))
|
newmap))))
|
||||||
|
|
||||||
(defnav
|
|
||||||
^{:doc "Like `walker` but maintains metadata of any forms traversed."}
|
|
||||||
codewalker
|
|
||||||
[afn]
|
|
||||||
(select* [this structure next-fn]
|
|
||||||
(i/walk-select afn next-fn structure))
|
|
||||||
(transform* [this structure next-fn]
|
|
||||||
(i/codewalk-until afn next-fn structure)))
|
|
||||||
|
|
||||||
(defdynamicnav subselect
|
(defdynamicnav subselect
|
||||||
"Navigates to a sequence that contains the results of (select ...),
|
"Navigates to a sequence that contains the results of (select ...),
|
||||||
but is a view to the original structure that can be transformed.
|
but is a view to the original structure that can be transformed.
|
||||||
|
|
@ -1286,3 +1290,11 @@
|
||||||
(cond-path (pred apred) STAY
|
(cond-path (pred apred) STAY
|
||||||
coll? [ALL p]
|
coll? [ALL p]
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
(def
|
||||||
|
^{:doc "Like `walker` but maintains metadata of any forms traversed."}
|
||||||
|
codewalker
|
||||||
|
(recursive-path [apred] p
|
||||||
|
(cond-path (pred apred) STAY
|
||||||
|
coll? [ALL-WITH-META p]
|
||||||
|
)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue