Update: it turns out Clojure has a built-in function file-seq that does (almost) exactly this. The difference is that you get a lazy sequence of File objects, not paths. Hooray for "batteries included"!
I was playing around with Clojure this morning, attempting to write a little photo viewer application. As part of this, I wound up writing a function that produces a lazy sequence of all the files that are descendants of a given directory. I was pretty happy with how it turned out, so I thought I’d share it. Here’s the code in its entirety:
(import [java.io File])
(defn dir-descendants [dir]
(let [children (.listFiles (File. dir))]
(map (memfn getPath) (filter (memfn isFile) children))
(map (memfn getPath) (filter (memfn isDirectory) children))))))