liveBook · Manning

Concatenation

As explained in Clojure: The Essential Reference

concat is a Clojure function that returns a lazy sequence containing the elements of two or more sequential collections in succession.

Clojure’s concat creates a lazy sequence containing the elements of zero or more sequential collections in succession. With no arguments it returns (); with one argument it accepts a sequential value or nil. section 9.3.9

Use concat with these practical expectations:

  • Inputs may be sequential collections or nil; a non-sequential input raises IllegalArgumentException. section 9.3.9
  • Consumption is lazy: concat realizes only enough input to satisfy the consumer. section 9.3.9

Concatenating changing sources

(def sold-icecreams [[:strawberry :banana :vanilla] '(:vanilla :chocolate) #{:hazelnut :pistachio}]) (apply concat sold-icecreams) ;; (:strawberry :banana :vanilla :vanilla :chocolate :hazelnut :pistachio)

How Clojure: The Essential Reference covers it

How deep it goes
Defines arities, contracts, exceptions, output, laziness, and implementation contrast with lazy-cat.
Examples
Uses mixed collection aggregation, traced realization, lazy-cat timing, formatted text, recursive batches, and Fibonacci numbers.
What it assumes
Assumes familiarity with Clojure sequences and collection types while teaching input contracts and laziness explicitly.
What you can do after
Apply it to combine fixed or runtime-known sequential collections while preserving lazy consumption.
How it connects
Connects lazy sequences, lazy-cat, apply, mapcat, transducers, and recursive sequence construction.

Also explained in

Compare how 10 books explain concatenation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.