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.

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

Members

Functions

each
void each(Array!T array)
Undocumented in source. Be warned that the author may not have intended to support it.
each
void each(Array!T* array)
Undocumented in source. Be warned that the author may not have intended to support it.

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

Meta