compacted range
1 import optional: no, some; 2 import ddash.utils: isFalsey; 3 assert([0, 1, 2, 0, 3].compact!(isFalsey).equal([1, 2, 3])); 4 assert([[1], [], [2]].compact!isFalsey.equal([[1], [2]])); 5 assert([some(2), no!int].compact!isFalsey.equal([some(2)])); 6 7 class C { 8 int i; 9 this(int i) { this.i = i; } 10 } 11 12 import std.algorithm: map; 13 auto arr = [new C(1), null, new C(2), null]; 14 assert(arr.compact.map!(a => a.i).equal([1, 2]));
0.0.1
Compacts a range