Yesterday, I posted about using Clojure zippers to solve the problem of automatically generating a Table of Contents. During my work with Clojure’s implementation of zippers, I noticed something interesting.
The zipper function creates (and returns) a new zipper object. Its parameters are the following (lifted straight from the documentation):
branch? – a function that takes a node of the zipper and returns a true/false if it is capable of having children (even if it currently does not). children – a function which, given a node in the zipper which is a branch, returns a seq (sequence) of its children. make-node – a function which, given a node and a sequence of its children, returns a new branch node with the supplied children. root – the root node of the data structure (which can also be any valid tree that the zipper to be constructed understands). At first, this was a bit impenetrable. Why doesn’t the zipper just know how to zip over its data? How many types of zippers are there, exactly?
...