Last active
January 14, 2017 17:34
-
-
Save benashford/a9ea85225f4984174235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn group-by-with-transducer [key-f xf data] | |
(let [ff (memoize (fn [k] (xf conj))) | |
r (reduce (fn [m d] | |
(let [k (key-f d) | |
v (get m k [])] | |
(if (reduced? v) | |
m | |
(assoc m k ((ff k) v d))))) | |
{} | |
data)] | |
(into {} | |
(map (fn [[k v]] [k ((ff k) (unreduced v))])) | |
r))) |
Yes, thanks for pointing it out, I've updated it now 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 4 I think it should
key-f
instead offirst