Last active
December 29, 2015 01:19
-
-
Save mudphone/7592124 to your computer and use it in GitHub Desktop.
From the Clojure Data Analysis Cookbook... an useful display of the lazy-seq macro.
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 lazy-read-csv | |
[csv-file] | |
(let [in-file (io/reader csv-file) | |
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))))] | |
(lazy csv-seq))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Buy the book, if you like this:
http://www.ericrochester.com/pages/announcements/clj-data-analysis/index.html