bearophile Wrote:

> From the len() code I have posted you can see there are other places where 
> you want to use len(), in particular to count the number of items that a lazy 
> generator (opApply for now) yields.
>
hmm...

import std.stdio, std.algorithm;

void main()
{
        bool pred(int x){ return x>2; }
        auto counter=(int count, int x){ return pred(x)?count+1:count; };
        int[] a=[0,1,2,3,4];
        auto lazylen=reduce!(counter)(0,a);
        writeln(lazylen); //2
}

Reply via email to