On Fri, Nov 21, 2008 at 12:03 AM, samppi <[EMAIL PROTECTED]> wrote: > > Is it possible to create a MapEntry from scratch? The reason why I'm > asking is because I want to mess with sequences of two-sized vectors, > and it would be really cool if I could use the key and val functions > on them rather than (get % 0) and (get % 1): > > (map #(str "Key:" (key %) "Value:" (val %)) [(map-entry :a 3) (map- > entry :b 2) (map-entry :a 1) (map-entry :c 0)])
Since Rich discouraged use of the MapEntry class, here are a couple of options. First, one thing worth remembering is that vectors are functions of their indexes, so you can do this and get rid of the "get"'s: (map #(str "Key: " (% 0) "Value: " (% 1)) [[:a 3] [:b 2] [:a 1] [:c 0]]) Second, if it was the use of (key) and (val) that you were most interested in, you could create your own (map-entry) function: user=> (defn map-entry [k v] (first {k v})) #'user/map-entry user=> (map #(str "Key:" (key %) "Value:" (val %)) [(map-entry :a 3) (map-entry :b 2) (map-entry :a 1) (map-entry :c 0)]) ("Key::aValue:3" "Key::bValue:2" "Key::aValue:1" "Key::cValue:0") HTH, - J. --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---