Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created January 10, 2022 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save run-dlang/0ad8dacc5c6d259dfcc2ff03aa8c730b to your computer and use it in GitHub Desktop.
Save run-dlang/0ad8dacc5c6d259dfcc2ff03aa8c730b to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io. Run with '-unit test'
/+dub.sdl:
dependency "sumtype" version="~>1.2.0"
dependency "emsi_containers" version="~>0.9.0"
+/
void main()
{
import std.range, std.stdio;
auto sum = 0.0;
auto count = stdin //Get an input range set up to read one line at a time
.byLine //Perform a transparent operation (as in the shell command tee)
.tee!(l => sum += l.length).walkLength;
writeln("Average line length: ", count ? sum / count : 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment