Java streams Vs LINQ Vs D

Jesse Phillips Jessekphillips+D at gmail.com
Wed Mar 27 17:08:30 PDT 2013


On Wednesday, 27 March 2013 at 22:19:01 UTC, bearophile wrote:
> Challenge 3: Selecting/Mapping
>
> Say we have a list of names and we would like to print “Hello” 
> in front of all the names:
>
> List<string> nameList1 = new List(){ "Anders", "David", "James",
>                                      "Jeff", "Joe", "Erik" };
> nameList1.Select(c => "Hello! " + c).ToList()
>          .ForEach(c => Console.WriteLine(c));
>
>
> 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.

Hmm, I would have thought this should work:

     auto nameList1 = ["Anders", "David", "James", "Jeff", "Joe",
"Erik"];
	 nameList1.copy( a => writeln("Hello! ", a) );

According std.range: "r(e); 	R is e.g. a delegate accepting an E."


More information about the Digitalmars-d mailing list