Skip to content

Instantly share code, notes, and snippets.

@nathanic
Last active December 11, 2015 22:18
Show Gist options
  • Save nathanic/4668048 to your computer and use it in GitHub Desktop.
Save nathanic/4668048 to your computer and use it in GitHub Desktop.
Clojure version of something josh was trying in Guava
(def input [["a" "apple"] ["a" "amazon"] ["b" "banana"] ["c" "clown"]])
(->> (group-by first input) ; now we have our keys pointing to lists of every key value pair with that key
(map (fn [[k v]] [k (map second v)])) ; for each key value pair, keep only the second parts of the values
(into {})) ; throw it into a hash map
;=> {"a" ("apple" "amazon"), "b" ("banana"), "c" ("clown")}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment