function | since v0.0-927 | clojure.core/partition-all | Edit |
(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.
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.
(defn partition-all
([n]
(fn [rf]
(let [a (array-list)]
(fn
([] (rf))
([result]
(let [result (if (.isEmpty a)
result
(let [v (vec (.toArray a))]
;;clear first!
(.clear a)
(unreduced (rf result v))))]
(rf result)))
([result input]
(.add a input)
(if (== n (.size a))
(let [v (vec (.toArray a))]
(.clear a)
(rf result v))
result))))))
([n coll]
(partition-all n n coll))
([n step coll]
(lazy-seq
(when-let [s (seq coll)]
(cons (take n s) (partition-all n step (drop step s)))))))