From d56ea62e001e959c6018104f1d608d266d457bdf Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Fri, 22 Jan 2016 19:45:20 -0800 Subject: [PATCH] reimplement stay-then-continue and continue-then-stay in terms of multi-path --- src/clj/com/rpl/specter.cljx | 37 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/clj/com/rpl/specter.cljx b/src/clj/com/rpl/specter.cljx index 74235a2..683dc0c 100644 --- a/src/clj/com/rpl/specter.cljx +++ b/src/clj/com/rpl/specter.cljx @@ -240,31 +240,6 @@ ancestry)) ))) -(defn stay-then-continue - "Navigates to the current element and then navigates via the provided path. - This can be used to implement pre-order traversal." - [& path] - (fixed-pathed-path [late path] - (select* [this structure next-fn] - (concat (next-fn structure) - (doall (mapcat next-fn (compiled-select late structure))))) - (transform* [this structure next-fn] - (compiled-transform late next-fn (next-fn structure)) - ))) - -(defn continue-then-stay - "Navigates to the provided path and then to the current element. This can be used - to implement post-order traversal." - [& path] - (fixed-pathed-path [late path] - (select* [this structure next-fn] - (concat (doall (mapcat next-fn (compiled-select late structure))) - (next-fn structure))) - (transform* [this structure next-fn] - (next-fn (compiled-transform late next-fn structure)) - ))) - - (defpath keypath [key] (select* [this structure next-fn] (next-fn (get structure key))) @@ -445,3 +420,15 @@ structure compiled-paths )))) + +(defn stay-then-continue + "Navigates to the current element and then navigates via the provided path. + This can be used to implement pre-order traversal." + [& path] + (multi-path STAY path)) + +(defn continue-then-stay + "Navigates to the provided path and then to the current element. This can be used + to implement post-order traversal." + [& path] + (multi-path path STAY))