Range golf challenge: apply predicate to a subrange, returning the original range modified.

Andrey Zherikov andrey.zherikov at gmail.com
Fri Oct 7 16:32:07 UTC 2022


On Friday, 7 October 2022 at 15:20:50 UTC, FeepingCreature wrote:
> On Friday, 7 October 2022 at 15:18:08 UTC, FeepingCreature 
> wrote:
>> `range.select` returns a subrange of `range`. What's desired 
>> is "`range`, but with the *subrange only* mapped to `modify`."
>
> For example!
>
> ```
> auto result = 10.iota.selectSubrange!isEven.mapSubrange!"a * 2";
>
> assert(result.equal([0, 1, 4, 3, 8, 5, 12, 7, 16, 9]));
> ```

```d
10.iota.map!(_ => _.isEven ? _*2 : _); // => [0, 1, 4, 3, 8, 5, 
12, 7, 16, 9]
```


More information about the Digitalmars-d mailing list