--- url: "https://martinfowler.com/articles/collection-pipeline/group-by.html" titulek: "group-by" h1: "group-by" popis: "" jazyk: "" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:35:14" znaku: 864 slov: 135 kodovani: "utf-8" sha256: "fd4f2f86d653f8f84daab508c38269a01e13785f1ecda427f37355a3f86072b3" --- This page describes an operation in the collection pipeline pattern. For more context read: - [Collection Pipeline Article](/articles/collection-pipeline) : An article explaining the collection pipeline pattern - [Operation Catalog](/articles/collection-pipeline#op-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.