--- url: "https://martinfowler.com/articles/collection-pipeline/concat.html" titulek: "concat" h1: "concat" popis: "" jazyk: "" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:35:17" znaku: 1412 slov: 230 kodovani: "utf-8" sha256: "be56c0b5397673b1944df80a912c6a7e8a7a353061f05755d44f2ad5e01483d3" --- 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. # concat Concatenates collections into a single collection ruby… ``` [1,2,3].concat([4,5]) # => [1, 2, 3, 4, 5] ``` clojure… ``` (concat [1 2 3] [4 5]) ;; => (1 2 3 4 5) ``` If you want to concatenate more than two collections, you'll find different languages have different approaches. ruby… ``` [1,2,3].concat([4,5]).concat([6]) # => [1, 2, 3, 4, 5, 6] ``` clojure… ``` (concat [1 2 3] [4 5] [6]) ;; => (1 2 3 4 5 6) ``` It's natural lisp style to allow functions to take a list of arguments, so that fits well for concatenation. Ruby's concat function only takes one argument, which you could see as a limitation, but is easily dealt with by chaining the concat. Languages that support infix operators usually have an operator to concatenate collections, in Ruby it's “+”. ruby… ``` [1,2,3] + [4,5] + [6] # => [1, 2, 3, 4, 5, 6] ``` Whenever you're using infix operators, you need to group them with parentheses to get them to chain properly. ruby… ``` ([1,2,3] + [4,5] + [6]).select(&:odd?) # => => [1, 3, 5] ``` And as usual with infix operators, they don't work well except at the head of the chain.