From fb6e1607ca7741a2109c372cb01ae65d99fde3f7 Mon Sep 17 00:00:00 2001 From: Chouser Date: Fri, 17 Oct 2008 21:34:54 +0000 Subject: Add combinations to lazy-seqs --- src/clojure/contrib/lazy_seqs/lazy_seqs.clj | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') 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)))) -- cgit v1.2.3-70-g09d2