Thanks for all your suggestions. Seems like a useful addition to
clojure.zip to me.
--
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated -
Hi,
while working on some XML data extraction I got an NPE which boiled down to
calling some zipper related functions on an empty vector or nil.
I didn't find a function in clojure.zip, clojure.data.zip or
clojure.data.zip.xml to test if an object passed to a function is actually
a zipper.
If you're using clojure.zip then a zipper is merely a vector with 3
specific keys (:zip/make-node, :zip/children, and :zip/branch?) in the
metadata which the zipper algorithms use to manipulate and traverse the
data structure. You can trivially check using something like (and (vector?
z)
I wrote a function for this in
laser.
https://github.com/Raynes/laser/blob/e351444a09e5c81b900767e955edf62558c33fd6/src/me/raynes/laser/zip.clj#L38
(defn zipper?
Checks to see if the object has zip/make-node metadata on it (confirming it
to be a zipper.
[obj]
(contains? (meta obj)