On Sunday, 26 January 2014 at 13:24:06 UTC, matovitch wrote:

Zipping an index array is uglier in my opinion... ;-)

Extract it into a function and stick it into your library, it's extremely useful :)

import std.range;
import std.algorithm;
import std.stdio;

auto enumerate(R)(R r) {
        return zip(sequence!((a,n) => a[0]+n)(0), r);
}

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


We need generic enumerate() in Phobos :(

Reply via email to