next returns the sequence after removing the first element. It accepts any seqable collection or nil, and returns nil when nothing remains. section 10.1
Its practical distinctions are:
- Unlike rest, next returns nil rather than an empty list at the end. section 10.1
- Together with first, next supports recursive traversal and nil punning: the remaining sequence itself can serve as the termination test. section 10.1
Recursive traversal
(defn next-loop [coll] (loop [xs (seq coll) results []] (if xs (recur (next xs) (conj results (first xs))) results))) (next-loop (range 10)) ;; [0 1 2 3 4 5 6 7 8 9]
