Hi all,

I have a Java Map contains Map of Maps/List (JSON like map) and have
to convert to Clojure map (This happens at Java - Clojure Interop), So
I have written a converter function 'as-clj-map' by modifying the
clojure walk functions, It works fine, but consume lot of cpu when the
data structure is quit big. Any suggestions to improve this code?


(defn walk-coll [inner outer form]
  (cond
    (instance? java.util.List form) (outer (into  [] (map inner
form)))
    (instance? java.util.Map form)  (outer (into  {} (map inner
form)))
    :else (outer form)))

(defn postwalk-coll [f form]
  (walk-coll (partial postwalk-coll f) f form))

(defn as-clj-map [m]
  (let [f (fn [[k v]] (if (string? k) [(keyword k) v] [k v]))]
    (postwalk-coll (fn [x] (if (instance? java.util.Map x) (into {}
(map f x)) x)) m)))


Thanks and regards.
-Jestan Nirojan

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to