foreach loop

wobbles via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 3 08:55:12 PST 2015


On Tuesday, 3 November 2015 at 15:42:16 UTC, Edwin van Leeuwen 
wrote:
> On Tuesday, 3 November 2015 at 15:29:31 UTC, Namal wrote:
>>> writefln("Count is: %s", arr
>>>   .filter!(a => a==true)
>>>   .sum);
>>>
>>> // Note: std.algorithm.sum is the same as
>>> // std.algorithm.reduce!((a,b)=a+b);
>>
>
> Shouldn't you be using walkLength instead of sum, since you are 
> counting the left over values?
>
> import std.range : walkLength;
> writefln("Count is: %s", arr
>   .filter!(a => a==false)
>   .walkLength);

That would work also yes.
Be interesting to know which is more efficient actually - I 
suspect they're very similar.


More information about the Digitalmars-d-learn mailing list