/////////////////////////////////////////////
1 //import std.stdio : writeln; 2 import std.range : iota; 3 import std.algorithm : map; 4 //import std.array : array; 5 import std.math : approxEqual; 6 import std.algorithm.comparison : equal; 7 8 import vest.range : expandNested; 9 10 11 assert(iota(20, 25, 1) 12 .map!(x => iota(21, x, 1)) 13 .expandNested 14 .equal([21, 21, 22, 21, 22, 23])); 15 16 assert([ 17 [1,2].getItarable, 18 iota(10, 16).getItarable, 19 ] 20 .expandNested 21 .equal([1, 2, 10, 11, 12, 13, 14, 15])); 22 23 assert([ 24 [1.1,2.1].getItarable!float, 25 iota(10, 16).getItarable!float, 26 ] 27 .expandNested 28 .approxEqual([1.1, 2.1, 10.0, 11.0, 12.0, 13.0, 14.0, 15])); 29 30 31 interface iTest { 32 int get() const; 33 } 34 class Test1 : iTest 35 { 36 int i; 37 this(int i) {this.i = i;} 38 int get() const {return i*i;} 39 } 40 class Test2 : iTest 41 { 42 int i; 43 this(int i) {this.i = i;} 44 int get() const {return i*i*i;} 45 } 46 47 assert([ 48 [1,2,3] 49 .map!(x => new Test1(x)) 50 .getItarable, 51 [1,2,3] 52 .map!(x => new Test1(x)) 53 .getItarable, 54 ] 55 .expandNested 56 .map!(x => x.get) 57 .equal([1, 4, 9, 1, 4, 9])); 58 59 assert([ 60 [1,2,3] 61 .map!(x => new Test1(x)) 62 .getItarable!iTest, 63 [1,2,3] 64 .map!(x => new Test2(x)) 65 .getItarable!iTest, 66 ] 67 .expandNested 68 .map!(x => x.get) 69 .equal([1, 4, 9, 1, 8, 27]));