Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Scheme

Idiom #143 Iterate alternatively over two lists

Iterate alternatively over the elements of the lists items1 and items2. For each iteration, print the element.

Explain what happens if items1 and items2 have different size.

(map (lambda (x)
       (display x)
       (newline))
     (foldr append '()
            (map list items1 items2)))
(doseq [i (interleave items1 items2)]
  (println i))

interleave can receive any number of items, but truncates when any of them is exhausted

New implementation...