Created
January 30, 2011 15:48
-
-
Save raek/802959 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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