From 7dbe4dc524cdc52596d7c17f47f4490f55b827f9 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Thu, 19 Oct 2017 10:38:43 -0400 Subject: [PATCH] Use defnav with regex* rather than defrichnav. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nathan: vals is how collect / collect-one are implemented. You should use defnav rather than defrichnav since it handles that parameter in the background. defrichnav exists since the compiler doesn't do certain inlining optimizations, so defrichnav allows the handling of vals to be inlined manually. This is only important for navigators which do very little work (like keypath) – I think regexes are expensive enough that the inlining optimization won't be noticeable. --- src/clj/com/rpl/specter/navs.cljc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/clj/com/rpl/specter/navs.cljc b/src/clj/com/rpl/specter/navs.cljc index 20a90ee..0f0069c 100644 --- a/src/clj/com/rpl/specter/navs.cljc +++ b/src/clj/com/rpl/specter/navs.cljc @@ -622,15 +622,12 @@ (do-keypath-transform vals structure key next-fn) )) -(defrichnav ^{:doc "Navigates to the lazy sequence of successive matches when a regex is applied to a string, navigating to nil if it does not exist or nothing is found."} - ;; Setting the value to NONE will remove it from the collection.} - regex* - [re] - (select* [this vals structure next-fn] +(defnav regex* [re] + (select* [this structure next-fn] (doseqres NONE [s (re-seq re structure)] - (next-fn vals s))) - #_(transform* [this vals structure next-fn] - (next-fn (clojure.string/replace structure re vals)))) + (next-fn s))) + (transform* [this structure next-fn] + (clojure.string/replace structure re next-fn))) (defrichnav ^{:doc "Navigates to the key only if it exists in the map. Setting the value to NONE