Range golf challenge: apply predicate to a subrange, returning the original range modified.
Andrey Zherikov
andrey.zherikov at gmail.com
Fri Oct 7 16:35:04 UTC 2022
On Friday, 7 October 2022 at 16:32:07 UTC, Andrey Zherikov wrote:
> ```d
> 10.iota.map!(_ => _.isEven ? _*2 : _); // => [0, 1, 4, 3, 8, 5,
> 12, 7, 16, 9]
> ```
You can even generalize this:
```d
alias mapSubrange(alias filter, alias transform) = map!(_ =>
filter(_) ? transform(_) : _);
10.iota.mapSubrange!(isEven, _ => _*2);
```
More information about the Digitalmars-d
mailing list