"A seq is like a logical cursor." | ||
--Rich Hickey |
Sequences (commonly known as seqs) are a way to sequentially consume a succession of data. Like Java iterators, they let a user begin consuming elements from the head and proceed realizing one element after another. However, unlike Java iterators, sequences are immutable. Also, since sequences are only a view of the underlying data, they do not modify the storage structure of the data.
What makes sequences stand apart is they are not data structures per se; rather, they are a data abstraction over a stream of data. The data may be produced by an algorithm or a data source connected to an I/O operation. For example, the function resultset-seq
accepts a JDBC java.sql.ResultSet
instance as an argument and produces lazily-realized rows of data as a seq.
Clojure data structures can be turned into sequences using the seq
function. For example, (seq [:a :b :c :d])
returns a sequence. Calling seq
over an empty collection returns...