Skip to content

Instantly share code, notes, and snippets.

@tebeka
Created February 8, 2011 06:06
Show Gist options
  • Save tebeka/815967 to your computer and use it in GitHub Desktop.
Save tebeka/815967 to your computer and use it in GitHub Desktop.
Reading CSV
(ns csv
(import com.csvreader.CsvReader))
(defn csv-seq
"Return a lazy sequence of records (vectors) from CSV file"
[filename]
(let [csv (CsvReader. filename)
read-record (fn []
(when (.readRecord csv)
(into [] (.getValues csv))))]
(take-while (complement nil?) (repeatedly read-record))))
(defn csv-header-seq
"Return a lazy sequence of record (maps) from CSV file with header"
[filename]
(let [records (csv-seq filename)]
(map #(zipmap (first records) %) (rest records))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment