I keep needing to go to the last (rightmost) child of a loc (generally
after appending it).
(Or I failed to spot the proper idiom.)
So I wrote last-child:
(defn last-child [loc]
(last (take-while identity (iterate zip/right (zip/down loc)))))
but it feels a bit overkill because of all this repeated calls to
zip/right. I could write:
(defn down-right
"Returns the loc of the rightmost child of the node at this loc, or
nil if no children"
[loc]
(let [[node path] loc
cs (vec (zip/children loc))]
(when (seq cs)
(with-meta [(peek cs) {:l (pop cs)
:pnodes (if path (conj (:pnodes path) node)
[node])
:ppath path
:r nil}] ^loc))))
but it would mess with zippers internals: I don't like to have that in
user code.
Would it be a useful addition to clojure.zip?
Christophe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---