On 07/04/2013 07:04 AM, Andrei Alexandrescu wrote:
Evidence we've done the right thing by emphasizing ranges instead of
opApply.

http://www.reddit.com/r/programming/comments/1hl2qr/rust_07_released/
https://mail.mozilla.org/pipermail/rust-dev/2013-June/004599.html

Andrei

Well, probably, but implementing ranges is still too tedious.
It is very likely that rust is going to fix that.

It should be as simple as:

auto map(alias a,R)(R r){
    foreach(x;r)
        yield a(x);
}

auto filter(alias a,R)(R r){
    foreach(x;r)
        if(a(x))
            yield x;
}

auto take(R)(R r,size_t i){
    while(i--&&!r.empty){
        yield r.front;
        r.popFront();
    }
}

auto joiner(R,S)(R r,S s){
    if(r.empty) break;
    foreach(x;r.front)
        yield x;
    r.popFront();
    foreach(rr;r){
        yield s;
        foreach(x;rr)
            yield x;
    }
}

auto cprod(R,S)(R r,S s){
    foreach(x;r)
        foreach(y;s)
            yield tuple(x,y);
}

One can get painfully close with basically no effort (DMD regressed on it though):
http://dpaste.dzfl.pl/baa538af


Ideally the compiler would automatically turn definitions similar to those above into auto return function templates that create instances of range types.

The issue is how to design it to make it useful for generic wrapper ranges that should forward the source range capabilities.

Reply via email to