Why Phobos is cool
Jesse Phillips
Jesse.K.Phillips+D at gmail.com
Wed Jul 8 05:50:30 UTC 2020
On Tuesday, 7 July 2020 at 23:38:26 UTC, Paul Backus wrote:
> On Monday, 6 July 2020 at 20:47:36 UTC, Jordan Wilson wrote:
>>
>> 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
Not in one liner form
readText("emu.sift").csvReader!(Tuple!(double))(' ').map!(x =>
x[0]).maxElement.writeln;
I wanted to us
https://dlang.org/phobos/std_range.html#transversal
But that didn't work for a few reasons. It would be nice because
this example isn't good if trying to do something with say the 25
element.
More information about the Digitalmars-d
mailing list