Created
January 14, 2015 17:55
-
-
Save kindlychung/3ff3b591a74af81d4124 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn mapify | |
"Return a seq of maps like {:name \"Edward Cullen\" :glitter-index 10}" | |
[rows] | |
(let [;; headers becomes the seq (:name :glitter-index) | |
headers (map #(get headers->keywords %) (first rows)) | |
;; unmapped-rows becomes the seq | |
;; (["Edward Cullen" "10"] ["Bella Swan" "0"] ...) | |
unmapped-rows (rest rows)] | |
;; Now let's return a seq of {:name "X" :glitter-index 10} | |
(map (fn [unmapped-row] | |
;; We're going to use map to associate each header with its | |
;; column. Since map returns a seq, we use "into" to convert | |
;; it into a map. | |
(into {} | |
;; notice we're passing multiple collections to map | |
(map (fn [header column] | |
;; associate the header with the converted column | |
[header ((get conversions header) column)]) | |
headers | |
unmapped-row))) | |
unmapped-rows))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment