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.

Reply via email to