algorithm's .filter!() by range key

cym13 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 9 12:44:34 PST 2016


On Tuesday, 9 February 2016 at 20:40:44 UTC, Charles wrote:
> This seems to be true of any range function really... is there 
> a way to access the key within my range?
>
> Example of what I want to do:
>
> auto x = [1,2,3,4,5];
> x.filter( x_key % 2 == 1 ).sum(); // sum odd elements in array

x.filter!(x_key => x_key % 2 == 1).sum();


More information about the Digitalmars-d-learn mailing list