Skip to content

Commit

Permalink
use sum instead of reduce in example code
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Oct 6, 2014
1 parent eefb1e1 commit 6465b09
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions std/stdio.d
Expand Up @@ -1340,7 +1340,7 @@ Params:
buf = Buffer used to store the resulting line data. buf is
resized as necessary.
terminator = Line terminator (by default, $(D '\n')). Use
$(XREF ascii, newline) for portability (unless the file was opened in
$(XREF ascii, newline) for portability (unless the file was opened in
text mode).
Returns:
Expand Down Expand Up @@ -1691,7 +1691,7 @@ Char = Character type for each line, defaulting to $(D char).
keepTerminator = Use $(D KeepTerminator.yes) to include the
terminator at the end of each line.
terminator = Line separator ($(D '\n') by default). Use
$(XREF ascii, newline) for portability (unless the file was opened in
$(XREF ascii, newline) for portability (unless the file was opened in
text mode).
Example:
Expand All @@ -1701,10 +1701,10 @@ import std.algorithm, std.stdio, std.string;
void main()
{
auto file = File("file.txt"); // Open for reading
const wordCount = file.byLine() // Read lines
.map!split // Split into words
.map!(a => a.length) // Count words per line
.reduce!((a, b) => a + b); // Total word count
const wordCount = file.byLine() // Read lines
.map!split // Split into words
.map!(a => a.length) // Count words per line
.sum(); // Total word count
writeln(wordCount);
}
----
Expand Down Expand Up @@ -1829,7 +1829,7 @@ Char = Character type for each line, defaulting to $(D immutable char).
keepTerminator = Use $(D KeepTerminator.yes) to include the
terminator at the end of each line.
terminator = Line separator ($(D '\n') by default). Use
$(XREF ascii, newline) for portability (unless the file was opened in
$(XREF ascii, newline) for portability (unless the file was opened in
text mode).
Example:
Expand Down

0 comments on commit 6465b09

Please sign in to comment.