Skip to content

Instantly share code, notes, and snippets.

/join-csvs.clj Secret

Created December 29, 2013 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/055c885f955723401590 to your computer and use it in GitHub Desktop.
Save anonymous/055c885f955723401590 to your computer and use it in GitHub Desktop.
(require '[clojure.data.csv :as csv]
'[clojure.java.io :as io])
(defn open-csv [file]
(with-open [in-file (io/reader file)]
(doall
(csv/read-csv in-file))))
(defn map-csv-row [fields file]
(map (fn [row] (zipmap fields row))
(open-csv file)))
(defn id-extract [col i]
(merge col
{(:id i) (merge i (get col (:id i)))}))
(defn add-csv
[hm fields file]
(reduce id-extract
hm
(map-csv-row fields file)))
(defn -main []
(add-csv (add-csv {} [:id :first :middle :last] "input.csv")
[:id :age :month] "input2.csv"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment