Commits

Miki Tebeka committed 198dd12 Merge

Merge with default

Comments (0)

Files changed (1)

     (fn [record]
       (zipmap (keys record) (map #(convert % (record %)) (keys record))))))
 
+; Default delimiter
+(def *delimiter* \,)
+; Default charset
+(def *charset* "UTF-8")
+
 (defn- record-seq 
   "Reutrn a lazy sequence of records from a CSV file"
   [filename delimiter charset]
 
   With header map will be header->value, otherwise it'll be position->value.
   `conversions` is an optional map from header to a function that convert the
-  value."
-  [filename & {:keys [delimiter charset headers? convert]
-               :or {delimiter *delimiter* charset *charset*}}]
+  value.
+  
+  Additional keyword arguments are 'charset' for the file character set and
+  'delimiter' for record delimiter"
+  [filename & {:keys [headers? convert charset delimiter]
+               :or {charset *charset* delimiter *delimiter*}}]
    (let [records (record-seq filename delimiter charset)
          convert (make-converter convert)
          headers (if headers? (first records) (range (count (first records))))]
      (map convert
           (map #(zipmap headers %) (if headers? (rest records) records)))))
 
-(defn- indexes [coll]
-  (range (count coll)))
-
-(defn- gen-headers 
-  "Generate headers for combinations of headers supplied by the user (which can
-  be a nil, map or a vector, and the first record (which can also be nil, map or
-  vector)."
-  [headers record]
-  (cond
-    (and (nil? headers) (nil? record)) nil
-    (and (nil? headers) (vector? record)) nil
-    (vector? headers) (zipmap headers (indexes headers))
-    (map? headers) headers
-    (map? record) (zipmap (keys record) (indexes record))))
-
-(defn sort-record [record headers]
-  (if (vector? record)
-    record
-    (if headers
-      (sort-by :record headers)
-      (assert aaaa
-      record)))
-
+; (defn- indexes [coll]
+;   (range (count coll)))
+; 
+; (defn- gen-headers 
+;   "Generate headers for combinations of headers supplied by the user (which can
+;   be a nil, map or a vector, and the first record (which can also be nil, map or
+;   vector)."
+;   [headers record]
+;   (cond
+;     (and (nil? headers) (nil? record)) nil
+;     (and (nil? headers) (vector? record)) nil
+;     (vector? headers) (zipmap headers (indexes headers))
+;     (map? headers) headers
+;     (map? record) (zipmap (keys record) (indexes record))))
+; 
+; (defn sort-record [record headers]
+;   (if (vector? record)
+;     record
+;     (if headers
+;       (sort-by :record headers)
+;       (assert aaaa
+;       record)))
+; 
 ; (defn write-csv
 ;   [records filename & {:keys [delimiter charset headers]
 ;                :or {delimiter *delimiter* charset *charset*}}]