Skip to content

Instantly share code, notes, and snippets.

@candera
Created March 9, 2010 13:30
Show Gist options
  • Save candera/326567 to your computer and use it in GitHub Desktop.
Save candera/326567 to your computer and use it in GitHub Desktop.
Function to return a lazy sequence of all the descendant files of a directory.
(defn dir-descendants
"Creates a lazy sequence of files by recursively walking
a directory tree and returning all the files it finds."
[dir]
(let [children (.listFiles (File. dir))]
(lazy-cat
(map (memfn getPath) (filter (memfn isFile) children))
(mapcat dir-descendants
(map (memfn getPath) (filter (memfn isDirectory) children))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment