aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorscgilardi <scgilardi@gmail.com>2009-02-11 18:15:49 +0000
committerscgilardi <scgilardi@gmail.com>2009-02-11 18:15:49 +0000
commitdd066717145e5d05acf1be903540d307d0cc7d70 (patch)
treea7d98f890bdde7aa169044f9f5a44946507f1826
parent2acc2451a1e12eed91dfdfb7759328673ccd353c (diff)
fix issue 9: lazy_seqs add partition-all from Jason Wolfe
-rw-r--r--src/clojure/contrib/lazy_seqs.clj11
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]