| 1 |
template map(fun...) |
| 2 |
{ |
| 3 |
auto map(R)(R r) |
| 4 |
{ |
| 5 |
return MapResult!(fun, R)(r); |
| 6 |
} |
| 7 |
} |
| 8 |
|
| 9 |
struct MapResult(alias fun, R) |
| 10 |
{ |
| 11 |
R _input; |
| 12 |
|
| 13 |
@property bool empty() { return _input.length == 0; } |
| 14 |
@property auto front() { return fun(_input[0]); } |
| 15 |
void popFront() { _input = _input[1..$]; } |
| 16 |
} |
| 17 |
|
| 18 |
struct Foo |
| 19 |
{ |
| 20 |
int baz(int v) |
| 21 |
{ |
| 22 |
static int id; |
| 23 |
return v + id++; |
| 24 |
} |
| 25 |
void bar() |
| 26 |
{ |
| 27 |
auto arr1 = [1, 2, 3]; |
| 28 |
auto arr2 = [4, 5, 6]; |
| 29 |
arr1.map!( |
| 30 |
// lambda1 |
| 31 |
i => |
| 32 |
arr2.map!( |
| 33 |
// lambda2 |
| 34 |
j => |
| 35 |
baz(i + j) |
| 36 |
) |
| 37 |
); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
void main() {} |