Hi,

Am 14.05.2009 um 17:12 schrieb Daniel Lyons:

That would be wonderful. I have wrapped OpenCSV for my own purposes
but would of course prefer not having another library dependency. My
code wound up like this:


(import 'java.io.FileReader 'au.com.bytecode.opencsv.CSVReader))

(defn read-csv [filename]
  (let [reader (CSVReader. (FileReader. filename))]
    (map vec (take-while identity (repeatedly #(.readNext reader))))))

I'm doing the same. I cannot judge the quality of OpenCVS but up to
now I had no problems. I thought about using fnparse to build a clojure
CSV parser, but I'm not sure how hard this would be. Let's see with
what Stuart comes up.

I built a function which reads the first row in the file as headers and
creates a sequence of structures of the rest.

(defn entry-seq
  [rdr]
  (let [hdrs      (map keyword (.readNext rdr))
        entry-s   (apply create-struct hdrs)
        entry-seq (fn entry-seq []
                    (lazy-seq
                      (when-let [entry (.readNext rdr)]
(cons (apply struct entry-s entry) (entry- seq)))))]
    (entry-seq)))

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to