liveBook · Manning

Chunk-append

As explained in Clojure: The Essential Reference

chunk-append is a Clojure function that adds an element to a ChunkBuffer while space remains.

chunk-append adds an element to a mutable ChunkBuffer while capacity remains. It is an internal building block for constructing chunks used in chunked sequential processing, not a general-purpose collection operation. section 10.12

Use the function with this contract:

  • Call (chunk-append b x), where b is a ChunkBuffer and x can be any object. section 10.12
  • Create the buffer with chunk-buffer, append values, then call chunk to obtain an IChunk for chunk-cons. section 10.12
  • Appending to a full buffer raises ArrayIndexOutOfBoundsException. section 10.12

Build a chunk

(def b (chunk-buffer 10)) (chunk-append b 0) (chunk-append b 1) (chunk-append b 2) (def first-chunk (chunk b)) (chunk-cons first-chunk ()) ;; (0 1 2)

How Clojure: The Essential Reference covers it

How deep it goes
Defines inputs, buffer lifecycle, and exceptions, then demonstrates chunk construction without detailing implementation internals.
Examples
Demonstrates integer accumulation, conversion with chunk, and consumption through chunk-cons.
What it assumes
Assumes familiarity with Clojure sequences and requires distinguishing internal mutable buffers from returned chunks.
What you can do after
Apply it via Clojure's chunking API to assemble values before consuming them as an IChunk.
How it connects
Connects ChunkBuffer with chunk, chunk-cons, chunked sequences, and lazy sequential processing.

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.