Created
March 9, 2010 13:30
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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