Logo

Programming-Idioms

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

Idiom #141 Iterate in sequence over two lists

Iterate in sequence over the elements of the list items1 then items2. For each iteration print the element.

void print_seq(const auto& ...xs)
{
 (std::for_each(std::begin(xs), std::end(xs), 
           [](const auto& x) { std::cout << x; }), ...);
}

 std::list xs { "hi", "there", "world" }, ys { "lo" "thar" };

 print_seq(xs, ys);
;; for side effects
(doseq [x (concat items1 items2)]
   (println x))

concat concatenates two or more sequences https://clojuredocs.org/clojure.core/concat
doseq for side effects. Alternatively for to produce a new sequence https://clojuredocs.org/clojure.core/doseq
https://clojuredocs.org/clojure.core/for

New implementation...
< >
BBaz