Programs manipulate data. At the lowest level, programs work with structures such as strings, lists, vectors, maps, sets, and trees. At a higher level, these same data structure abstractions crop up again and again. For example:
In Clojure, all these data structures can be accessed through a single abstraction: the sequence (or seq).
A seq (pronounced “seek”) is a logical list. It’s logical because Clojure does not tie sequences to the concrete implementation details of the list data structure. Instead, the seq is an abstraction that can be used everywhere.
Collections that can be viewed as seqs are called seq-able (pronounced “SEEK-a-bull”). In this chapter, you’ll meet a variety of seq-able collections:
You’ll also meet the sequence library, a set of functions that can work with any seq-able. Because so many things are sequences, the sequence library is much more powerful and general than the collection API in most languages. The sequence library includes functions to create, filter, and transform data. These functions act as the collection API for Clojure, and they also replace many of the loops you would write in an imperative language.
In this chapter, you will become a power user of Clojure sequences. You’ll see how to use a common set of very expressive functions with a wide range of datatypes. Then, in the next chapter (Chapter 4, Functional Programming), you’ll learn the functional style in which the sequence library is written.