Skip to content

Instantly share code, notes, and snippets.

@evilsneer
Created April 8, 2021 10:58
Show Gist options
  • Save evilsneer/621cd82a258b1e571d0929838285bea3 to your computer and use it in GitHub Desktop.
Save evilsneer/621cd82a258b1e571d0929838285bea3 to your computer and use it in GitHub Desktop.
Clojure seq of maps -> csv
(defn write-csv [writer row-data]
(let [columns (->>
row-data
first
(into (sorted-map))
keys)
headers (map name columns)
rows (->> row-data
(map (comp vals #(into (sorted-map) %))))]
(csv/write-csv writer (lazy-seq (cons headers rows)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment