10 Sequential Processing

 

This chapter is about functions and macros for sequential processing. These functions typically transform their input into a sequence (if it’s not already) and produce another sequence. Although sequential functions can be used with any collection type offering a sequential interface, they tend to perform at their best with pure sequential input/output.

Sequential processing can be broadly categorized as follows:

  • Partitioning: isolate a consecutive portion of the sequence by index, number of items, or using a custom predicate.
  • Selection: retrieve items from the sequence but not necessarily as a consecutive selection.
  • Transformation: apply a function to each item in the sequence to produce another sequence.
  • Combining: combination of multiple sequences to form another sequence.
  • Chunking: process a sequence by groups of multiple elements instead of one at a time.

If we look at the partitioning operations in particular, there are many of them. Their naming convention is consistent but it might be confusing to pick the right function. For this reason, partitioning functions has been further divided into groups:

10.1  rest, next, fnext, nnext, ffirst, nfirst and butlast

10.2  drop, drop-while, drop-last, take, take-while, take-last, nthrest, nthnext

10.3  keep and keep-indexed

10.4  mapcat

10.5  interpose and interleave

10.6  partition, partition-all and partition-by

10.7  flatten

10.8  distinct, dedupe and distinct?

10.9  take-nth

10.10  split-at and split-with

10.11  when-first

10.12  chunk-cons, chunk-first, chunk-rest, chunk-next, chunk-buffer, chunk-append and chunk