open:zip-next

zip-next

;; zip-walk takes a transformation function f and a zipper z.
;; f takes a location and returns location. Applies f
;; to the nodes in the zipper maintaining the original nesting.
 
(require '[clojure.zip :as zip])
 
(defn zip-walk [f z]
  (if (zip/end? z)
    (zip/root z)
    (recur f (zip/next (f z)))))
 
(zip-walk
  (fn [loc] 
    (if (zip/branch? loc) 
      loc 
      (zip/edit loc * 2)))
  (zip/vector-zip [1 2 [3 4]]))
 
;; [2 4 [6 8]]


  • open/zip-next.txt
  • 마지막으로 수정됨: 2022/06/11 15:01
  • 저자 127.0.0.1