InputStream.opApply

Overload foreach statements to read the stream line by line and call the supplied delegate with each line or with each line with line number.

The string passed in line may be reused between calls to the delegate. Line numbering starts at 1. Breaking out of the foreach will leave the stream position at the beginning of the next line to be read. For example, to echo a file line-by-line with line numbers run:

Stream file = new BufferedFile("sample.txt");
foreach(ulong n, char[] line; file)
{
    writefln("line %d: %s", n, line);
}
file.close();

Meta