Java streams Vs LINQ Vs D
Chris Cain
clcain at uncg.edu
Wed Mar 27 17:20:23 PDT 2013
On Wednesday, 27 March 2013 at 22:19:01 UTC, bearophile wrote:
> In Phobos there is no forEach(), so you have to use foreach:
>
> auto nameList1 = ["Anders", "David", "James", "Jeff",
> "Joe", "Erik"];
> foreach (name; nameList1)
> writeln("Hello! ", name);
>
>
> The only advantage I see of a forEach() over foreach() is that
> it's usable at the end of an UFCS chain.
import std.algorithm : chain, map, copy;
import std.stdio;
void main() {
["Anders", "David", "James", "Jeff", "Joe", "Erik"]
.map!(str => chain("Hello! ", str, "\n"))
.copy(stdout.lockingTextWriter());
}
Will do it as well.
More information about the Digitalmars-d
mailing list