From 050384e0fd7104e0410ead3b61d0572a60ac975c Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Sun, 21 Feb 2016 19:44:50 -0500 Subject: [PATCH] cleaner and more composable integration --- src/clj/com/rpl/specter/zipper.cljx | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/clj/com/rpl/specter/zipper.cljx b/src/clj/com/rpl/specter/zipper.cljx index e1bd055..bcf5eec 100644 --- a/src/clj/com/rpl/specter/zipper.cljx +++ b/src/clj/com/rpl/specter/zipper.cljx @@ -7,9 +7,17 @@ [com.rpl specter]) (:require [clojure [zip :as zip]])) -(def VECTOR-ZIP (view zip/vector-zip)) -(def SEQ-ZIP (view zip/seq-zip)) -(def XML-ZIP (view zip/xml-zip)) +(defpath zipper [constructor] + (select* [this structure next-fn] + (next-fn (constructor structure))) + (transform* [this structure next-fn] + (zip/root (next-fn (constructor structure))) + )) + +(def VECTOR-ZIP (zipper zip/vector-zip)) +(def SEQ-ZIP (zipper zip/seq-zip)) +(def XML-ZIP (zipper zip/xml-zip)) + (def NEXT (view zip/next)) (def RIGHT (view zip/right)) (def RIGHTMOST (view zip/rightmost)) @@ -17,23 +25,11 @@ (def DOWN (view zip/down)) (def LEFTMOST (view zip/leftmost)) (def UP (view zip/up)) -(def ROOT (view zip/root)) (defpath NODE [] (select* [this structure next-fn] (next-fn (zip/node structure)) ) (transform* [this structure next-fn] - (zip/root (zip/edit structure next-fn)) + (zip/edit structure next-fn) )) - -(defn edited [path update-fn] - (fixed-pathed-path [late path] - (select* [this structure next-fn] - (next-fn - (zip/edit structure - #(compiled-transform late update-fn %)))) - (transform* [this structure next-fn] - (next-fn - (zip/edit structure - #(compiled-transform late update-fn %))))))