partition-all

functionsince v0.0-927 clojure.core/partition-allEdit
(partition-all n)
(partition-all n coll)
(partition-all n step coll)

Details:

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.


See Also:


Source docstring:
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.
Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(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)))))))