Skip to content

Instantly share code, notes, and snippets.

@alexpw
Created December 21, 2012 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpw/4350075 to your computer and use it in GitHub Desktop.
Save alexpw/4350075 to your computer and use it in GitHub Desktop.
Merged implementation.
(defn x-group-by
([f g coll]
(persistent!
(reduce
(fn [ret x]
(let [k (f x)]
(assoc! ret k (g (get ret k) x))))
(transient {}) coll)))
([f coll]
(x-group-by f #(conj (or % []) %2) coll)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment