List Comprehension equivalent

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 17 12:29:49 PDT 2017


On Fri, Mar 17, 2017 at 07:21:50PM +0000, John Colvin via Digitalmars-d-learn wrote:
[...]
> reduce is a free function in std.algorithm. Just import it and you're
> away.
[...]

Also, there is now a variant of reduce called `fold`, that has a nicer
order of parameters, i.e., you can use it in UFCS chains:

	myData.map!(a => transform(a))
	      .fold!((a,b) => a + b)(0);

whereas `reduce` won't work this way because it has an incompatible
order of parameters.


T

-- 
There are three kinds of people in the world: those who can count, and those who can't.


More information about the Digitalmars-d-learn mailing list