Last active
December 23, 2015 15:42
-
-
Save spacepluk/f682f387fb3cd93f4d72 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
(defn java->clj | |
"Recursively transforms Java arrays into Clojure vectors, and Java Maps into | |
Clojure persistent maps. With option ':keywordize-keys true' will convert | |
keys from strings to keywords." | |
([x] (java->clj x :keywordize-keys false)) | |
([x & opts] | |
(let [{:keys [keywordize-keys]} opts | |
keyfn (if keywordize-keys keyword identity) | |
f (fn thisfn [x] | |
(cond | |
(seq? x) | |
(doall (map thisfn x)) | |
(coll? x) | |
(into (empty x) (map thisfn x)) | |
(instance? java.util.List x) | |
(vec (map thisfn x)) | |
(instance? java.util.Map x) | |
(into {} (for [[k v] x] [(keyfn k) (thisfn v)])) | |
:else x))] | |
(f x)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment