Skip to content

Instantly share code, notes, and snippets.



Last active Dec 23, 2015
What would you like to do?
(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]
(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