Why is there no range iteration with index by the language?
Dukc
ajieskola at gmail.com
Wed Jun 10 16:02:59 UTC 2020
On Wednesday, 10 June 2020 at 15:34:57 UTC, Steven Schveighoffer
wrote:
> My biggest problem with enumerate is that you can't bind the
> tuple to parameters for something like map:
>
> arr.enumerate.map!((idx, val) => ...)
>
> doesn't work. Instead you have to do:
>
> arr.enumerate.map!((tup) => ...)
>
> And use tup[0] and tup[1].
>
> -Steve
```
alias tupArg(alias func) = x => func(x.expand);
arr.enumerate.map!(tupArg!((idx, val) => ...))
```
Somewhat heavy on syntax, but better than `tup[0]` or `tup[1]`
IMO.
More information about the Digitalmars-d-learn
mailing list