deepIterate

Iterates a tree-like structure that exposes an input range interface and calls each element with a function.

bool
deepIterate
(
alias Fun
string member = ""
Range
A...
)
(
Range range
,
auto ref A a
)

Parameters

Fun

The function called for each element. When its return type is bool, and if it returns true, the iterations are stopped.

member

The name of the member that gives the real Range.

mode

The iteration mode (breadth-first or depth-first).

range Range

The root element.

a A

The variadic parameters passed to Fun (after the element).

Return Value

Type: bool

True if the iterations have stopped, false otherwise.

Examples

// creates a tree
Item root = new Item;
root.populate;
root[0].populate;
root[1].populate;

int cnt, a;

// count the population
deepIterate!((e) => ++cnt)(root);
assert(cnt == 7);

// previous content is consumed
root.populate;
root[0].populate;
root[1].populate;

// the delegate result is used to stop the iteration
deepIterate!((Item e, ref int p){++p; --cnt; return cnt == 4;})(root, a);
assert(cnt == 4);
assert(a == 3);

Meta