chunk-buffer creates a mutable intermediate buffer for assembling a chunk during chunked sequential processing. It wraps a Java object array and is intended as an internal artifact, not ordinary application data. section 10.12
Use the buffer through this small contract:
- Call (chunk-buffer capacity) with a positive integer capacity. section 10.12
- Add values with (chunk-append b x), then convert the completed buffer with (chunk b). section 10.12
- Pass the resulting chunk to chunk-cons when constructing a chunked lazy sequence. section 10.12
- Treat capacity as fixed: appending to a full buffer raises ArrayIndexOutOfBoundsException. section 10.12
Assemble 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)
Listing 10.13. → Chunked sequences
(chunk-cons [chunk rest]) (chunk-first [s]) (chunk-rest [s]) (chunk-next [s]) (chunk-buffer [capacity]) (chunk-append [b x]) (chunk [b]) (chunked-seq? [s])
Browse the related chunked-sequence API alongside chunk-buffer, chunk creation, chunk consumption, and chunk detection. section 10.12
