[Issue 13903] std.array.removeIf for associative arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 31 16:27:36 UTC 2018


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

Seb <greensunny12 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12 at gmail.com

--- Comment #1 from Seb <greensunny12 at gmail.com> ---
Not sure whether such one/two-liners would be accepted to Phobos.

---
import std.experimental.all;

auto removeIf(alias pred, AA)(AA aa)
{
    aa.byPair.filter!(not!pred).each!(e => aa.remove(e.key));
    return aa;
}

void main()
{
    auto aa = ["a" : 1, "b" : 2];
    aa.removeIf!(a => a.key == "a").writeln;
}
---

But efficiency and bug-proneness are two good points.

--


More information about the Digitalmars-d-bugs mailing list