each

Iterates the given array and calls the given callable for each element.

Use this instead of foreach when the array may expand during iteration.

template each(alias callable, T)
void
each
(
ref Array!T array
)
if (
is(ReturnType!(typeof(
(
T t
)
=> callable(t)
)) == void)
)

Parameters

callable

the callable to call for each element

array

the array to iterate

Examples

static immutable expected = [2, 3, 4, 5];

Array!int array;

foreach (e ; expected)
    array.push(e);

int[] result;
array.each!((e) {
    result ~= e;
});

assert(result == expected);

See Also

Suggestion Box / Bug Report