Skip to content

Instantly share code, notes, and snippets.

@raek
Created January 30, 2011 15:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/802959 to your computer and use it in GitHub Desktop.
Save raek/802959 to your computer and use it in GitHub Desktop.
(defn alternate
"Take two collections and return a lazy seq of alternating items
from the first coll, then from the second etc until one of the
collections is runs out of elements. Unlike interleave, the first
collection may contain one element more than the second, which will
be included in the resulting laz seq."
[c1 c2]
(lazy-seq
(when-first [x c1]
(cons x (alternate c2 (rest c1))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment