Can you simplify nested Indexed types?

Salih Dincer salihdb at hotmail.com
Tue Dec 27 16:40:31 UTC 2022


On Tuesday, 27 December 2022 at 15:09:11 UTC, Sergei Nosov wrote:
> Consider, I have the following code:
>
> ```d
>     auto a = [3, 6, 2, 1, 5, 4, 0];
>
>     auto indicies = iota(3);
>     auto ai = indexed(a, indicies);
>     ai = indexed(ai, iota(2));
>
>     writeln(ai);
> ```

Why not use `filter()`, isn't it important to filter out what's 
in range?

```d
import std.algorithm;
import std.stdio;
import std.range;

int[] a = [3, 6, 2, 1, 5, 4, 0];
auto indicies = iota(3);
auto ai = a.filter!(e => e >= indicies.front
                       && e <= indicies.back);
ai.writeln; // [2, 1, 0]
```
SDB at 79


More information about the Digitalmars-d-learn mailing list