You're viewing version 1.2.0 of vector-zip. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

vector-zip

clojure.zip

  • (vector-zip root)
Returns a zipper for nested vectors, given a root vector

1 Example top

  • (require '[clojure.zip :as zip])
    
    (defn zip-map [f loc]
      " Map f over every node of the zipper.
        The function received has the form (f node-value loc),
        the node value and its location"
      (loop [z loc]
        (if (zip/end? z)
          (zip/root z) ; perhaps you can call zip/seq-zip or zip/vector-zip?
          (recur (zip/next (zip/edit z f z))))))
    
    ;; Multiply by 100 every node in the tree
    user=> (zip-map (fn [n nx] (if (vector? n) n (* n 100) )) (zip/vector-zip '[5 [10 20 30] [1 2 3] ]))
    ;; Be careful! the returned result by zip/root is not a zipper anymore!
    [500 [1000 2000 3000] [100 200 300]]
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/zip.clj:44 top

(defn vector-zip
  "Returns a zipper for nested vectors, given a root vector"
  {:added "1.0"}
  [root]
    (zipper vector?
            seq
            (fn [node children] (with-meta (vec children) (meta node)))
            root))
Vars in clojure.zip/vector-zip: defn fn meta seq vec vector? with-meta
Used in 0 other vars

Comments top

No comments for vector-zip. Log in to add a comment.