Skip to content

Instantly share code, notes, and snippets.

@geoffeg
Last active December 20, 2015 23:39
Show Gist options
  • Save geoffeg/6214614 to your computer and use it in GitHub Desktop.
Save geoffeg/6214614 to your computer and use it in GitHub Desktop.
Convert a map's values into their proper type.
; 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