Skip to content

Instantly share code, notes, and snippets.

@biggert
Created May 15, 2013 15:23
Show Gist options
  • Save biggert/5584807 to your computer and use it in GitHub Desktop.
Save biggert/5584807 to your computer and use it in GitHub Desktop.
Why does parse-row work but add-bates-number not?
(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