Hello all, I am starting to learn clojure. I would appreciate comments on the utility function below. Coding style, idiomatic Clojure, comment style, efficiency, naming conventions, indentations (used slime) ... anything I should improve :)
(defn seq-to-multimap [s key-fn] "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" (reduce (fn [amap item] (let [key (key-fn item)] (assoc amap key (if-let [it (amap key)] (conj it item) (list item))))) {} s)) user> (seq-to-multimap [1 :key :key 2 3 3 nil] #(identity %1)) {nil (nil), 3 (3 3), 2 (2), :key (:key :key), 1 (1)} Would it be better to have this function to create a list of lists using an equality op instead? Thank you! Boris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---