Skip to content

Instantly share code, notes, and snippets.

@tomjack
Created January 30, 2011 15:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tomjack/73c9627bb97c36bbe6e0 to your computer and use it in GitHub Desktop.
(defn interleave*
([c1] c1)
([c1 c2]
(lazy-seq
(let [s1 (seq c1) s2 (seq c2)]
(if (and s1 s2)
(cons (first s1) (cons (first s2)
(interleave* (rest s1) (rest s2))))
(or s1 s2)))))
([c1 c2 & colls]
(lazy-seq
(let [ss (filter identity (map seq (conj colls c2 c1)))]
(when (seq ss)
(concat (map first ss) (apply interleave* (map rest ss))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment