generator

Transforms delegate into lazy range. Generation is stopped, when genfunc returns Maybe!T.nothing.

generator
(
T
)
(
Maybe!T delegate
()
genfunc
)

Examples

Example

1 assert( (() => Maybe!int(1)).generator.take(10).equal(1.repeat.take(10)) );
2 assert( (() => Maybe!int.nothing).generator.empty);
3 assert( (() 
4         {
5             static size_t i = 0;
6             return i++ < 10 ? Maybe!int(1) : Maybe!int.nothing;
7         }
8         ).generator.equal(1.repeat.take(10)));
9 
10 class A {}
11 auto a = new A();
12 
13 assert( (() => Maybe!A(a)).generator.take(10).equal(a.repeat.take(10)) );
14 assert( (() => Maybe!A.nothing).generator.empty);
15 assert( (() 
16         {
17             static size_t i = 0;
18             return i++ < 10 ? Maybe!A(a) : Maybe!A.nothing;
19         }
20         ).generator.equal(a.repeat.take(10)));

Meta