(defn seq-to-multimap
"takes a sequence s of possibly repeating elements
and converts it to a map, where keys are obtained by applying key-
fn
to elements of s and values are sequence of all elements of s with
the particular key"
[s key-fn]
(apply merge-with concat
(map (fn [x] {(key-fn x) [x]}) s)))
Here's a more concise, but probably significantly slower version ....
-Jason
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---