Logo

Programming-Idioms

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

Idiom #166 Concatenate two lists

Create the list ab containing all the elements of the list a, followed by all the elements of the list b.

std.range;
int[] a, b;
auto ab = chain(a, b);

ab is a lazy iterator iterator that's with the same elements as the result of the concatenation (a ~ b) but without allocation.
int[] a, b;
auto ab = a ~ b;

Using built-in arrays
(def ab (concat a b))

New implementation...