ClojureDocs

Nav

Namespaces

next

clojure.zip

Available since 1.0
  • (next loc)
Moves to the next loc in the hierarchy, depth-first. When reaching
the end, returns a distinguished loc detectable via end?. If already
at the end, stays there.
1 Example
;; 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]]
See Also

Moves to the previous loc in the hierarchy, depth-first. If already at the root, returns nil.

Added by reborg
0 Notes
No notes for next