diff options
author | Chouser <chouser@n01se.net> | 2008-10-17 21:34:54 +0000 |
---|---|---|
committer | Chouser <chouser@n01se.net> | 2008-10-17 21:34:54 +0000 |
commit | fb6e1607ca7741a2109c372cb01ae65d99fde3f7 (patch) | |
tree | bb60869e721b17fe3b218d5e845b398e4c15ccf6 /src/clojure | |
parent | 9fd93e1cdbf6f5662dea0c441b4bfd3c9125625b (diff) |
Add combinations to lazy-seqs
Diffstat (limited to 'src/clojure')
-rw-r--r-- | src/clojure/contrib/lazy_seqs/lazy_seqs.clj | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/clojure/contrib/lazy_seqs/lazy_seqs.clj b/src/clojure/contrib/lazy_seqs/lazy_seqs.clj index 17fe1a69..429700de 100644 --- a/src/clojure/contrib/lazy_seqs/lazy_seqs.clj +++ b/src/clojure/contrib/lazy_seqs/lazy_seqs.clj @@ -86,3 +86,14 @@ (map #(cons f %) (permutations r))) (rotations x)) (list nil))) + +(defn combinations + "Returns a lazy seq of all combinations built of one item from each seq given. + See also (doc for)" + [& acs] + (let [step (fn step [head [s & cs :as acs]] + (if acs + (mapcat #(step (conj head %) cs) s) + (list head)))] + (when acs + (step [] acs)))) |