We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 36ff9d1 commit 432eb1bCopy full SHA for 432eb1b
index.dd
@@ -243,20 +243,17 @@ Modern convenience.
243
Modeling power.
244
Native efficiency.)
245
----
246
-#!/usr/bin/env rdmd
247
-import std.range, std.stdio;
248
-
249
// Compute average line length for stdin
250
void main()
251
{
252
- ulong lines = 0, sumLength = 0;
253
- foreach (line; stdin.byLine())
254
- {
255
- ++lines;
256
- sumLength += line.length;
257
- }
+ import std.range, std.stdio;
+
+ auto sum = 0.0;
+ auto count = stdin.byLine
+ .tee!(l => sum += l.length).walkLength;
258
writeln("Average line length: ",
259
- lines ? cast(double) sumLength / lines : 0.0);
+ count ? sum / count : 0);
260
}
261
262
))
0 commit comments