Created
August 13, 2013 16:23
-
-
Save geoffeg/6222902 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
; Thanks to http://stackoverflow.com/questions/18202661/casting-values-of-a-map-to-their-proper-types-in-clojure | |
; for the basis for this, I needed to also support cases where a value in `input` was empty when the cast occured. | |
(def input {:a "1" :b "2.5" :c "more" :d "string" :e "keys" :f ""}) | |
(def typetrans {:a #(Long/parseLong %) :b #(Double/parseDouble %) :f #(Integer/parseInt %)}) | |
(defn cast-fields [csvmap] | |
(reduce-kv | |
(fn [acc k v] | |
(update-in acc [k] #(if-not (clojure.string/blank? %) (v %)))) | |
input typetrans)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment