-
-
Save anonymous/055c885f955723401590 to your computer and use it in GitHub Desktop.
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
(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