From 747b08090977315a638b67238907b914f0598a29 Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Sun, 24 Apr 2016 10:42:19 -0400 Subject: [PATCH] added INNER-RIGHT and INNER-LEFT --- src/clj/com/rpl/specter/zipper.cljx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/clj/com/rpl/specter/zipper.cljx b/src/clj/com/rpl/specter/zipper.cljx index bcf5eec..0f1b7f6 100644 --- a/src/clj/com/rpl/specter/zipper.cljx +++ b/src/clj/com/rpl/specter/zipper.cljx @@ -26,6 +26,32 @@ (def LEFTMOST (view zip/leftmost)) (def UP (view zip/up)) +(defn- inner-insert [structure next-fn inserter mover backer] + (let [to-insert (next-fn []) + inserts (reduce + (fn [z e] (-> z (inserter e) mover)) + structure + to-insert + )] + (if backer + (reduce (fn [z _] (backer z)) inserts to-insert) + inserts) + )) + +(defpath INNER-RIGHT [] + (select* [this structure next-fn] + (next-fn [])) + (transform* [this structure next-fn] + (inner-insert structure next-fn zip/insert-right zip/right zip/left) + )) + +(defpath INNER-LEFT [] + (select* [this structure next-fn] + (next-fn [])) + (transform* [this structure next-fn] + (inner-insert structure next-fn zip/insert-left identity nil) + )) + (defpath NODE [] (select* [this structure next-fn] (next-fn (zip/node structure))