Hey everyone,
I was working with an object that implements java.util.Map today, and
I had to turn it into a Clojure map.

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Map.html

I cam up with this utility fn

(defn read-map
  "Designed to turn a java.util.Map into a Clojure map."
  [a-map]
  (into {}
         (map
          #(hash-map (.getKey %) (.getValue %))
          (seq a-map))))

What if hash-map automatically cast a java.util.Map to a Clojure map?
Here's a proposed hash-map*

(defn hash-map*
  ([] (hash-map))
  ([& keyvals]
     (if (= (count keyvals) 1)
       (if (instance? java.util.Map (first keyvals))
         (read-map (first keyvals))
         (apply hash-map keyvals)) ;throws proper exception
       (apply hash-map keyvals))))

Is this auto-casting a desired behavior?  If not, does anyone want
read-map in contrib (c.c.map-utils)?

Sean

-- 
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