(partition-all n) (partition-all n coll) (partition-all n step coll)
Returns a lazy sequence of lists like partition, but may include partitions with fewer than n items at the end. Returns a stateful transducer when no collection is provided.
(partition 4 [0 1 2 3 4 5 6 7 8 9])
;;=> ((0 1 2 3) (4 5 6 7))
(partition-all 4 [0 1 2 3 4 5 6 7 8 9])
;;=> ((0 1 2 3) (4 5 6 7) (8 9))
(partition-all 2 4 [0 1 2 3 4 5 6 7 8 9])
;;=> ((0 1) (4 5) (8 9))
;; Caution: Partitioning lazy sequence code freeze
(def l [1 2 3 4 5])
;create a simple lazy sequence function testing only
;(rdr l) returns a lazy sequence from l
(def rdr (fn reader[x] (cons (first x) (lazy-seq (reader (rest x))))))
;the line below will freeze
(doall (partition-all 2 (rdr l)) )
;add-in a take-while statement do exit the lazy sequence on nil
(doall (partition-all 2 (take-while (complement nil?) (rdr l))))