On Monday, 21 June 2021 at 03:59:10 UTC, someone wrote:
I often need to iterate through a filtered collection (associative array) as following:

```d
string strComputerIDunwanted = "WS2"; /// associative array key to exclude

foreach (strComputerID, udtComputer; udtComputers) { /// .remove!(a => a == strComputerIDunwanted) ... ?

   if (strComputerID != strComputerIDunwanted) {

      ...

   }

}
```

Is there a way to filter the collection at the foreach-level to avoid the inner if ?

An associative array is not a range but a struct, so it is extra work to create a range from the AA to apply range functions.

You can get a range from it by using something like std.array.byPair() but for this usage you would be better of with your own function or template.


Reply via email to