std.algorithm missing for_each?

Meta jared771 at gmail.com
Wed Feb 5 05:24:55 PST 2014


On Wednesday, 5 February 2014 at 12:18:15 UTC, Idan Arye wrote:
> Your `foreach` is ugly because you need to look closely to see 
> the boundary between the functional chain and the iterative 
> execution.
>
> In this case, adding a block makes things much more elegant:
>
>
>     foreach (e; someInputRange
>                .filter!()
>                .map!())
>     {
>             e.someOperation();
>     }

I think that's a bit of an exaggeration. A hypothetical each() 
function would almost always be at the end of a UFCS chain, 
making it clear that it's iterating and consuming the result. 
This is no worse than putting .array at the end of a chain to 
force evaluation (and is actually much clearer about intent).


More information about the Digitalmars-d mailing list