Andrea Fontana:

So, is there any lazy way to do it?

Take my code and put it inside a struct, add empty, popFront and front.

Otherwise return an impure take of a filter closure from a function that keeps the set. Something like (untested):

auto firstDistinct(Range)(Range r, size_t n) {
    bool[ForeachType!(Range)] mySet;
    return f.filter!((k) {
        if (k in mySet)
            return false;
        mySet[k] = true;
        return true;
    }).take(n);
}

Bye,
bearophile

Reply via email to