diff options
author | scgilardi <scgilardi@gmail.com> | 2009-02-20 21:35:46 +0000 |
---|---|---|
committer | scgilardi <scgilardi@gmail.com> | 2009-02-20 21:35:46 +0000 |
commit | 64d79207eed0fe057a19fe4d3d0f6b714a63c69a (patch) | |
tree | b54acdf6a0614af23029df8f32c3c7619c3c0d31 /src | |
parent | eb4a7db1b6558faf84108cba0cfd8bae8af3c0ba (diff) |
fix issue 28: add step arg to partition-all, also fix doc string for rand-elt, partition-all patch based on one from H. Duerer
Diffstat (limited to 'src')
-rw-r--r-- | src/clojure/contrib/seq_utils.clj | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/clojure/contrib/seq_utils.clj b/src/clojure/contrib/seq_utils.clj index 745bd2b2..ef6ebfcf 100644 --- a/src/clojure/contrib/seq_utils.clj +++ b/src/clojure/contrib/seq_utils.clj @@ -125,15 +125,16 @@ (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] - (lazy-seq - (when (seq s) - (cons (take n s) - (partition-all n (drop n s)))))) - +(defn partition-all + "Returns a lazy sequence of lists like clojure.core/partition, but may + include lists with fewer than n items at the end." + ([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))))))) + (defn shuffle "Return a random permutation of coll" [coll] @@ -141,6 +142,7 @@ (java.util.Collections/shuffle l) (seq l))) -(defn rand-elt [s] +(defn rand-elt "Return a random element of this seq" + [s] (nth s (rand-int (count s)))) |