Created
July 13, 2009 06:49
-
-
Save fffej/145970 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn join-all | |
"Join the lists provided using f to select an element each time" | |
[f & lists] | |
(let [l (remove empty? lists)] | |
(when-not (empty? l) | |
(let [n (reduce f (map first l)) | |
c (count (filter (partial = true) (map (fn [x] (= (first x) n)) l))) | |
r (map (fn [x] (if (= (first x) n) (rest x) x)) l)] | |
(lazy-seq | |
(concat | |
(repeat c n) | |
(apply join-all (cons f r)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment