Fork me on GitHub
#rewrite-clj
<
2024-05-21
>
Noah Bogart13:05:47

is there an equivalent to tree-seq or the zipper api?

borkdude13:05:20

Shouldn’t be hard to write yourself

Noah Bogart13:05:06

probably not, no, i'm just doing some performance testing and didn't want to dive into using the zipper api if it's too slow for my current needs

borkdude13:05:53

Oh zipper API, I thought just the Node stuff. How would a tree-seq on a zipper make sense?

Noah Bogart14:05:27

lol it might not! i'm very unfamiliar with it, so i'm just experimenting at the moment.

borkdude14:05:07

I think I know what you might be getting at though. There is z/next to iterate through all the nodes

Noah Bogart14:05:43

you don't have to build one for me, i don't think i'm going to end up using the zipper api in any real way

lilactown16:05:47

I typically reach for zippers when tree-seq is not enough but you could easily write

(defn zipseq
  [z]
  (lazy-seq
    (cons (z/node z)
          (when-let [zn (z/next z)]
            (zipseq zn)))))

borkdude17:05:43

This kind of defeats the purpose of zippers, you can build such a tree-seq entirely without zippers too

Noah Bogart17:05:42

lol my goal was to test how much time it takes to traverse the different representations of a file of clojure code