Created
May 15, 2013 15:23
-
-
Save biggert/5584807 to your computer and use it in GitHub Desktop.
Why does parse-row work but add-bates-number not?
This file contains 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
(defn parse-row | |
"Parse a row of text applying the headers in a keyword map" | |
[headers & opts] | |
(let [p #(parse %1 opts)] | |
(comp (partial zipmap headers) first p))) | |
(defn add-bates-number | |
"Add the bates-number key (and value) to the collection" | |
[h id-ord] | |
(comp #(conj {:bates-number (get %1 (keyword (nth h id-ord)))} %1))) | |
(defn parse-lines | |
"Parse the specified sequence of lines using the row as a header which will | |
be applied to the rest of the sequence returning maps. | |
The text qualifier and delimiter characters will be automatically determined" | |
([lines] | |
(parse-lines lines 0)) | |
([lines id-ord] | |
(let [hrow (first lines) | |
qualifier (get-qualifier hrow) | |
delimiter (get-delimiter qualifier hrow) | |
h (parse-header hrow :delimiter delimiter :quote-char qualifier)] | |
(map (#(add-bates-number %1) h id-ord) | |
(lazy-seq | |
(map (#(parse-row %1 :delimiter delimiter :quote-char qualifier) h) | |
(rest lines))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment