Created
July 3, 2013 18:08
-
-
Save fbmnds/5921134 to your computer and use it in GitHub Desktop.
Memory Leak?
This file contains hidden or 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 lazy-read-csv | |
| "This one has lazily reads from the file and generates the CSV data. | |
| It will leak if the sequence is not fully consumed." | |
| ([csv-file] | |
| (let [in-file (io/text-reader csv-file) ;; FB: io/reader | |
| csv-seq (csv/read-csv in-file) | |
| lazy (fn lazy [wrapped] | |
| (lazy-seq | |
| (if-let [s (seq wrapped)] | |
| (cons (first s) (lazy (rest s))) | |
| (.Close in-file))))] ;; FB: .close | |
| (lazy csv-seq)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment