Alternate signs in a range

bearophile bearophileHUGS at lycos.com
Sun Jan 26 05:49:32 PST 2014


Stanislav Blinov:

> We need generic enumerate() in Phobos :(

It will come soon :-)
https://github.com/D-Programming-Language/phobos/pull/1866
(Take a look at my comment about foreach there)


This also shows we need a good syntax to unpack tuples:

> void main() {
> 	auto myRange = iota(0,10);
> 	auto result = myRange.enumerate.map!(a => a[0] & 1 ? -a[1] : 
> a[1]);
> 	result.writeln;
> }

It could be written like:

myRange.enumerate.map!(t{i, x} => i % 2 ? -x : x);

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list