Any guide to stream (string) processing in D? | Re: Any python-like generator patterns in D?

bearophile bearophileHUGS at lycos.com
Thu Feb 21 08:55:20 PST 2013


> import std.stdio, std.algorithm, std.string;
>
> void main() {
>     auto gen = File("infile.txt")
>                .byLine()
>                .map!chomp
>                .map!toUpper
>                .map!(line => "Line: " ~ line);
>
>     writefln("%-(%s\n%)", gen);
> }

Or faster:


import std.stdio, std.algorithm, std.string;

void main() {
     auto gen = File("infile.txt")
                .byLine()
                .map!(line => "Line: " ~ line.chomp.toUpper);

     writefln("%-(%s\n%)", gen);
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list