Why Phobos is cool

Paul Backus snarwin at gmail.com
Tue Jul 7 23:38:26 UTC 2020


On Monday, 6 July 2020 at 20:47:36 UTC, Jordan Wilson wrote:
>
> Just now I wanted to find the max value of a column in a text 
> file, my thinking went "Excel? It'll take ages to load...I'll 
> just google awk or something...hang on a minute, didn't I read 
> somewhere about D oneliners?"
>
> echo 'import std; void main() { 
> File("emu.sift","r").byLine.map!(a => a.splitter(" 
> ").front.to!double).maxElement.writeln; }' | dmd -run -
>
> Thanks!
>
> Jordan

IMO this still doesn't hold a candle to the awk version:

     awk '{ if ($1 > max) max = $1 } END { print max }'

With better library functions, though, the D version could be 
much, much nicer. Something like:

     stdin.byRecord.map(r => r.fields[0]).maxElement


More information about the Digitalmars-d mailing list