Last active
December 20, 2015 23:39
-
-
Save geoffeg/6214614 to your computer and use it in GitHub Desktop.
Convert a map's values into their proper type.
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
; Given a map where the values are numeric types contained in a string | |
; Convert the values to the type defined in a map of field types. | |
(mapv #(case ({"one" :int, "point-two" :float} (key %)) | |
:int {(key %) (Integer/parseInt (val %))} | |
:float {(key %) (Float/parseFloat (val %))} | |
{(key %) (val %)}) ; For strings, just return the original values if there was no type defined | |
{"one" "1", "point-two" ".2", "three" "three"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment