get element index when using each!(x)

Jacob Carlborg doob at me.com
Fri Sep 18 14:24:12 UTC 2020


On 2020-09-17 05:16, Paul Backus wrote:

> Worth knowing that the tuples you get from enumerate actually have named 
> members, so you can write:
> 
>      s.enumerate.each!(x => writeln(x.index, ":", x.value));

It actually works out of the box for `each`:

s.each!((index, value) => writeln(index, ":", value));

https://dlang.org/phobos/std_algorithm_iteration.html#.each

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list