Skip to content

Instantly share code, notes, and snippets.

@mudphone
Last active December 29, 2015 01:19
Show Gist options
  • Save mudphone/7592124 to your computer and use it in GitHub Desktop.
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.
(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)))
@mudphone
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment