Skip to content

Instantly share code, notes, and snippets.

@thbishop
Created January 14, 2015 22:07
Show Gist options
  • Save thbishop/a26a3a538a03c753ce77 to your computer and use it in GitHub Desktop.
Save thbishop/a26a3a538a03c753ce77 to your computer and use it in GitHub Desktop.
(def headers->keywords (array-map "Name" :name, "Glitter Index" :glitter-index))
(defn csv-headers [] (s/join "," (keys headers->keywords)))
(defn data->csv
"Converts ({:name 'Foo' :glitter-index 10} to 'Foo,10')"
[data]
(clojure.string/join "\n" (cons csv-headers ["foo,bar"]))))
; this returns
; "fwpd.core$csv_headers@2bfe621e\nfoo,bar"
; all we change is csv-headers from defn to def
(def headers->keywords (array-map "Name" :name, "Glitter Index" :glitter-index))
(def csv-headers (s/join "," (keys headers->keywords)))
(defn data->csv
"Converts ({:name 'Foo' :glitter-index 10} to 'Foo,10')"
[data]
(clojure.string/join "\n" (cons csv-headers ["foo,bar"])))
; this returns (which is what i'm after)
; "Name,Glitter Index\nfoo,bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment