Array.each

Eagerly iterate over each element in the array and call fun over each element. This should be used to iterate through const and immutable arrays.

Normally, the entire array is iterated. If partial iteration (early stopping) is desired, fun needs to return a value of type std.typecons.Flag!"each" (Yes.each to continue iteration, or No.each to stop).

template each(alias fun)
Flag!"each"
each
(
this Q
)
()
if (
is(typeof(unaryFun!fun(T.init)))
)

Members

Functions

each
Flag!"each" each()
Undocumented in source. Be warned that the author may not have intended to support it.

Imports

Flag (from std.typecons)
public import std.typecons : Flag, Yes, No;
Undocumented in source.
No (from std.typecons)
public import std.typecons : Flag, Yes, No;
Undocumented in source.
Yes (from std.typecons)
public import std.typecons : Flag, Yes, No;
Undocumented in source.
unaryFun (from std.functional)
public import std.functional : unaryFun;
Undocumented in source.

Structs

SList (from stdx.collections.slist)
struct SList(T) via public import stdx.collections.slist : SList;

Parameters

fun

unary function to apply on each element of the array.

Return Value

Yes.each if it has iterated through all the elements in the array, or No.each otherwise.

Complexity: O(n).

Examples

import std.typecons : Flag, Yes, No;

auto ia = immutable Array!int([1, 2, 3]);

static bool foo(int x) { return x > 0; }
static Flag!"each" bar(int x) { return x > 1 ? Yes.each : No.each; }

assert(ia.each!foo == Yes.each);
assert(ia.each!bar == No.each);

Meta