A Clojure sequence is an abstract data type. An abstract data type (or ADT) describes the behavior of a data structure without mandating a specific implementation. The following are the main properties of the abstraction:
- As the name implies it’s iterated sequentially: you cannot access the nth element without first accessing the nth -1 (and there are no gaps).
- It works like a stateless cursor: the iteration can only move forward.
- It’s persistent and immutable: like all other core data structures, sequences cannot be altered once created, but changes are possible in terms of a new sequence based on the previous (with structural sharing).
Optionally, sequences also support the following features (although they are not part of the contract):
- They are commonly (but not necessarily) lazy: the next element is produced only if that element is requested.
- Thew are also cached: the first access to the sequence elements produces a cached version of each item. Subsequent access to the sequence does not require further computation.
- They often apply "chunking" to improve performance. Chunking consists of processing a few more elements than requested, assuming the caller will soon move forward and access the rest of the sequence.