It would be nice if group-by
let users control the aggregated collection type and manipulate values before aggregation. It's a common scenarios when grouping a collection of maps according to one key, and maybe aggregating, even numerically according to another.
group-by
could be generalized like so:
(defn group-by
"Returns a map of the elements of coll keyed by the result of
f on each element. The value at each key will be a vector of the
corresponding elements, in the order they appeared in coll."
{:added "1.2"
:static true}
([kf coll]
(group-by kf [] coll))
([kf init coll]
(group-by kf identity init coll))
([kf vf init coll]
(group-by kf vf conj init coll))
([kf vf rf init coll]
(persistent!
(reduce
(fn [ret x]
(let [k (kf x)]
(assoc! ret k (rf (get ret k init) (vf x)))))
(transient {}) coll))))