Flattens a range one level deep by removing anything that's empty
Flattens a range all the way down
1 auto arrayOfArrays = [[[1]], [[]], [[2], [3]], [[4]]]; 2 3 // remove emptys 4 assert(arrayOfArrays.flatten.equal([[1], [], [2], [3], [4]])); 5 assert([[1], [], [2, 3], [4]].flatten.equal([1, 2, 3, 4])); 6 7 // remove empty all the way down 8 assert(arrayOfArrays.flattenDeep.equal([1, 2, 3, 4])); 9 10 import optional; 11 assert([some(some(3)), no!(Optional!int), some(some(2))].flattenDeep.equal([3, 2]));
Flattens a range one level deep by removing non truthy values.