-
-
Save jeaye/829d0944c39de52e17214da25f08e307 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
user=> (def data [{:a 0 :data :foo} {:a 1 :data :bar} {:a 0 :data :spam} {:a 2 :data :meow}]) | |
#'user/data | |
user=> (def grouped (reduce (fn [acc o] (update acc (:a o) #((fnil conj []) % (:data o)))) {} data)) | |
#'user/grouped | |
user=> grouped | |
{0 [:foo :spam] 1 [:bar] 2 [:meow]} | |
user=> (map (fn [[k v]] {:a k :items v}) grouped) | |
({:a 0 :items [:foo :spam]} {:a 1 :items [:bar]} {:a 2 :items [:meow]}) | |
user=> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment