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

1 // creates a tree
2 Item root = new Item;
3 root.populate;
4 root[0].populate;
5 root[1].populate;
6 
7 int cnt, a;
8 
9 // count the population
10 deepIterate!((e) => ++cnt)(root);
11 assert(cnt == 7);
12 
13 // previous content is consumed
14 root.populate;
15 root[0].populate;
16 root[1].populate;
17 
18 // the delegate result is used to stop the iteration
19 deepIterate!((Item e, ref int p){++p; --cnt; return cnt == 4;})(root, a);
20 assert(cnt == 4);
21 assert(a == 3);

Meta