#!/usr/bin/rdmd import std.stdio; import std.algorithm; void main() { bool[][][] clist=[[[true, true], [false, true]],[[true, false], [true, true]],[[false, true], [true, true]]]; auto x=0; writeln(clist); auto fpos=delegate bool(bool[][] a){return(a[x]!=[true,false]);}; auto fneg=delegate bool(bool[][] a){return(a[x]!=[false,true]);}; writeln("neg:",map!(delegate (bool[][] a){a[x][1]=true; return a;})(filter!(fneg)(clist))); writeln("pos:",map!(delegate (bool[][] a){a[x][0]=true; return a;})(filter!(fpos)(clist))); } outputs: [[[true, true], [false, true]], [[true, false], [true, true]], [[false, true], [true, true]]] neg:[[[true, true], [false, true]], [[true, true], [true, true]]] pos:[[[true, true], [false, true]], [[true, true], [true, true]], [[true, true], [true, true]]] if you change the order of the writeln you get:[[[true, true], [false, true]], [[true, false], [true, true]], [[false, true], [true, true]]] pos:[[[true, true], [false, true]], [[true, true], [true, true]]] neg:[[[true, true], [false, true]], [[true, true], [true, true]], [[true, true], [true, true]]]
What exactly is wrong? Removed OS specific since same happens on windows.
(In reply to comment #1) > What exactly is wrong? The second filter don't work, but it should. > > Removed OS specific since same happens on windows.
The map function changes the contents of the array, and unsurprisingly, that changes what the filter filters. This is not a bug in filter and map, but in your code. Reduced example: auto arr = [[false]]; writeln(arr.filter!(a => a[0]).map!(a => a[0] = true)); // [] writeln(arr.filter!(a => !a[0]).map!(a => a[0] = true)); // [true] writeln(arr.filter!(a => a[0]).map!(a => a[0] = true)); // [false] This is possibly caused by a misguided idea that the array is a value type.