This page describes an operation in the collection pipeline pattern. For more context read:
- Collection Pipeline Article: An article explaining the collection pipeline pattern
- Operation Catalog: The list of selected operations that I have these pages for.
group-by
Runs a function on each element and groups the elements by the result.
The group-by operation returns a hashmap keyed by the result of the supplied function
ruby…
["bat", "it", "a", "the"].group_by{|s| s.size} # => {3=>["bat", "the"], 2=>["it"], 1=>["a"]}
clojure…
(group-by count ["bat" "it" "a" "the"]) ;; => {3 ["bat" "the"], 2 ["it"], 1 ["a"]}
Since it naturally returns a hashmap, any downstream operations need to treat this map as a list of key-value pairs in order to continue the flow in the pipeline.