Created
February 7, 2020 21:16
-
-
Save aarkerio/aa517a820b26beb2d9bfba7f21df68c6 to your computer and use it in GitHub Desktop.
Clojure. Update some keys in a map.
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 str-to-int | |
"Convert some string keys in a map to integer" | |
[coll & int-keys] | |
(let [listed (set int-keys)] | |
(reduce-kv #(assoc %1 %2 (if (contains? listed %2 ) (Integer/parseInt %3) %3)) {} coll))) | |
(str-to-int {:qt "56" :kl "Some String" :wer "22" :jj "This is ok" :aa "456" :ll "Address"} :aa :qt :wer) | |
;; => {:qt 56, :kl "Some String", :wer 22, :jj "This is ok", :aa 456, :ll "Address"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment