> (defn mash > "Reduce a seq-able to a map. The given fn should return a 2-element tuple > representing a key and value in the new map." > [f coll] > (reduce > (fn [memo elem] > (let [[k v] (f elem)] > (assoc memo k v))) > {} coll))
I called this "map-map" in my utilities. Mine was even a bit more general, in that it could take multiple collections like "map". This allowed you to say thinks like (map-map vector s (iterate inc 0)) to get a map from elements of s to indices. Then Chouser pointed out [1] that map-map is equivalent to just (into {} (map f coll1 coll2 ...)) [1] http://groups.google.com/group/clojure/browse_thread/thread/134642cc76de17f7/b93b74fa4a6806cd?hl=en&q=utilities&lnk=ol& I still kind of like map-map, although I'm not sure if it's really any better than the idiom Chouser gave. YMMV, but I'm pretty sure the consensus was that map-map didn't belong in core, or probably even contrib. -Jason --~--~---------~--~----~------------~-------~--~----~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---