Created
February 8, 2011 06:06
-
-
Save tebeka/815967 to your computer and use it in GitHub Desktop.
Reading CSV
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
(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