wc in D: 712 Characters Without a Single Branch

Petar Petar
Tue Jan 28 21:43:31 UTC 2020


On Tuesday, 28 January 2020 at 21:40:40 UTC, Petar Kirov 
[ZombineDev] wrote:
> [snip]
>
>> import std.algorithm : count, splitter;
>> import std.stdio : File, writefln;
>> import std.typecons : Yes;
>>
>> void main(string[] args) {
>>     size_t lines, words, bytes;
>>     foreach (line; args[1].File.byLine(Yes.keepTerminator)) {
>>         lines++;
>>         bytes += line.count;
>>         words += line.splitter.count;
>>     }
>>     writefln!"%u %u %u %s"(lines, words, bytes, args[1]);
>> }
>
> [1]: 
> https://github.com/ethjs/ethjs-util/blob/e9aede668177b6d1ea62d741ba1c19402bc337b3/src/tests/test.index.js#L350

s/bytes/chars/



More information about the Digitalmars-d-announce mailing list