[Issue 9740] strange interaction between map and filter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 9 06:43:20 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=9740

Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |simen.kjaras at gmail.com
         Resolution|---                         |INVALID

--- Comment #3 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
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.

--


More information about the Digitalmars-d-bugs mailing list