chunk-first returns the first chunk of a chunked sequence. Use it when processing chunked data in groups rather than one element at a time; its input must satisfy the chunked-sequence abstraction. section 10.12
Use chunk-first alongside the chunked-sequence operations:
- Call (chunk-first s) to obtain an IChunk from s. section 10.12
- Reduce or transform that chunk, then rebuild the result with chunk-cons and continue with chunk-rest. section 10.12
- Treat chunk-* functions as low-level implementation-oriented tools; chunking primarily improves sequential-processing performance. section 10.12
Transforming the first chunk
A chunked mapper obtains the first chunk, creates a buffer sized to that chunk, applies f to each element, and emits the rebuilt chunk: (let [cf (chunk-first s) b (chunk-buffer (count cf))] ... (chunk-cons (chunk b) (map-chunked f (chunk-rest s)))). Applying (map-chunked inc (range 10000)) begins with (1 2 3 4 5 6 7 8 9 10). section 10.12
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, including chunk-cons, chunk-rest, chunk-next, chunk-buffer, chunk-append, chunk, and chunked-seq?. section 10.12
