Using "reduce" with user types

Kadir Erdem Demir via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 7 05:37:59 PST 2015


> auto sum = aArr.map!`a.count`.reduce!((a,b) => a + b);

Rikki Thanks a lot. It works.

Function map!"a.count"(aArr) surprises me a little.
Because when I read std.algorithm reference: `Implements the 
homonym function (also known as transform)`.

Which reminds me C++ transform and it will never used for 
returning a element of the struct.  I expect transform to modify 
the elements of the range but in D it seem to me it also used 
traversing the elements.

How can I imagine what "map" does in my mind, because it doesn't 
matches with the transform concept in my mind?

Regards
Kadir Erdem


More information about the Digitalmars-d-learn mailing list