diff options
Diffstat (limited to 'src/clojure/contrib/lazy_seqs.clj')
-rw-r--r-- | src/clojure/contrib/lazy_seqs.clj | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/clojure/contrib/lazy_seqs.clj b/src/clojure/contrib/lazy_seqs.clj index 53104124..9b40af26 100644 --- a/src/clojure/contrib/lazy_seqs.clj +++ b/src/clojure/contrib/lazy_seqs.clj @@ -23,6 +23,9 @@ ;; ;; rotations - returns a lazy seq of all the rotations of a seq ;; +;; partition-all - like built-in partition, but does not throw away +;; the last partition if it is too short +;; ;; (permutations and combinations used to be here, but have ;; been moved to combinatorics.clj) ;; @@ -71,6 +74,14 @@ (iterate inc 0) x) (list nil))) +(defn partition-all + "Lazily break s into chunks of length n (or less, for the + final chunk)." + [n s] + (when (seq s) + (lazy-cons (take n s) + (partition-all n (drop n s))))) + (defn random-permutation "Return a random permutation of coll" [coll] |