added traversed

This commit is contained in:
Nathan Marz 2016-11-07 07:47:36 -05:00
parent dfedd30b29
commit 508e1d08ed
2 changed files with 15 additions and 10 deletions

View file

@ -4,6 +4,7 @@
* Enhanced dynamic navigators to continue expanding if any other dynamic navs are returned * Enhanced dynamic navigators to continue expanding if any other dynamic navs are returned
* Added `eachnav` to turn any 1-argument navigator into a navigator that accepts any number of arguments, navigating by each argument in order * Added `eachnav` to turn any 1-argument navigator into a navigator that accepts any number of arguments, navigating by each argument in order
* `keypath` and `must` enhanced to take in multiple arguments for concisely specifying multiple steps * `keypath` and `must` enhanced to take in multiple arguments for concisely specifying multiple steps
* Added `traversed`
* Bug fix: Fix regression from 0.13.0 where [ALL FIRST] on a PersistentArrayMap that created duplicate keys would create an invalid PersistentArrayMap * Bug fix: Fix regression from 0.13.0 where [ALL FIRST] on a PersistentArrayMap that created duplicate keys would create an invalid PersistentArrayMap
* Bug fix: Fix problems with multi-path and if-path in latest versions of ClojureScript * Bug fix: Fix problems with multi-path and if-path in latest versions of ClojureScript
* Bug fix: Inline compiler no longer flattens and changes the type of sequential params * Bug fix: Inline compiler no longer flattens and changes the type of sequential params

View file

@ -842,21 +842,13 @@
(defdynamicnav filterer (defdynamicnav filterer
"Navigates to a view of the current sequence that only contains elements that "Navigates to a view of the current sequence that only contains elements that
match the given path. An element matches the selector path if calling select match the given path. An element matches the selector path if calling select
on that element with the path yields anything other than an empty sequence. on that element with the path yields anything other than an empty sequence."
The input path may be parameterized, in which case the result of filterer
will be parameterized in the order of which the parameterized selectors
were declared."
[& path] [& path]
(subselect ALL (selected? path))) (subselect ALL (selected? path)))
(defdynamicnav transformed (defdynamicnav transformed
"Navigates to a view of the current value by transforming it with the "Navigates to a view of the current value by transforming it with the
specified path and update-fn. specified path and update-fn."
The input path may be parameterized, in which case the result of transformed
will be parameterized in the order of which the parameterized navigators
were declared."
[path update-fn] [path update-fn]
(late-bound-nav [late (late-path path) (late-bound-nav [late (late-path path)
late-fn update-fn] late-fn update-fn]
@ -865,6 +857,18 @@
(transform* [this structure next-fn] (transform* [this structure next-fn]
(next-fn (compiled-transform late late-fn structure))))) (next-fn (compiled-transform late late-fn structure)))))
(defdynamicnav traversed
"Navigates to a view of the current value by transforming with a reduction over
the specified traversal."
[path reduce-fn]
(late-bound-nav [late (late-path path)
late-fn reduce-fn]
(select* [this structure next-fn]
(next-fn (reduce late-fn (compiled-traverse late structure))))
(transform* [this structure next-fn]
(next-fn (reduce late-fn (compiled-traverse late structure)))
)))
(def (def
^{:doc "Keeps the element only if it matches the supplied predicate. This is the ^{:doc "Keeps the element only if it matches the supplied predicate. This is the
late-bound parameterized version of using a function directly in a path."} late-bound parameterized version of using a function directly in a path."}