From 508e1d08edc63c061536dfb7053a2bfc722d57ea Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Mon, 7 Nov 2016 07:47:36 -0500 Subject: [PATCH] added traversed --- CHANGES.md | 1 + src/clj/com/rpl/specter.cljc | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index db7e333..7876359 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ * 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 * `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 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 diff --git a/src/clj/com/rpl/specter.cljc b/src/clj/com/rpl/specter.cljc index 810ae97..8461d5d 100644 --- a/src/clj/com/rpl/specter.cljc +++ b/src/clj/com/rpl/specter.cljc @@ -842,21 +842,13 @@ (defdynamicnav filterer "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 - 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." + on that element with the path yields anything other than an empty sequence." [& path] (subselect ALL (selected? path))) (defdynamicnav transformed "Navigates to a view of the current value by transforming it with the - 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." + specified path and update-fn." [path update-fn] (late-bound-nav [late (late-path path) late-fn update-fn] @@ -865,6 +857,18 @@ (transform* [this structure next-fn] (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 ^{: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."}