The Sequence Abstraction

A seq is a logical list: first, rest, and cons. Almost every collection (vectors, maps, sets, strings, Java collections, arrays) can be viewed as a seq with seq.

Sequence functions return seqs (often lazy), not the original collection type. Use into, vec, set, or mapv/filterv to get concrete collections back.

(seq [1 2 3])             ; (1 2 3)
(seq {:a 1 :b 2})         ; ([:a 1] [:b 2]): map entries
(seq "abc")               ; (\a \b \c)
(seq [])                  ; nil: the idiomatic emptiness test
(first [1 2 3])           ; 1
(rest [1 2 3])            ; (2 3)
(next [1])                ; nil (rest would return ())
(cons 0 [1 2])            ; (0 1 2)
(empty? [])               ; true
(when (seq coll) ...)     ; idiom: do something if non-empty
(map inc [1 2 3])         ; (2 3 4): a lazy seq, not a vector
(mapv inc [1 2 3])        ; [2 3 4]
(into #{} (map inc [1 2 3]))   ; #{4 3 2}
(into {} [[:a 1] [:b 2]]) ; {:a 1, :b 2}