On Sunday, 26 January 2014 at 13:21:24 UTC, Stanislav Blinov
wrote:
But it's easy to avoid the multiplication and replace it with
a conditional neg.
Bye,
bearophile
How would you do this ?
map!(a => (a.index & 1) ? a : -a)([1, 2]) ? (index field isn't
available of course)
import std.range;
import std.algorithm;
import std.stdio;
void main() {
auto myRange = iota(0,10);
auto index = sequence!((a,n) => a[0]+n)(1);
auto result = myRange.zip(index).map!(a => a[1] & 1 ? a[0] :
-a[0]);
result.writeln;
}
Zipping an index array is uglier in my opinion... ;-)