code D'ish enough? - ignore previous post with same subject

Thorstein via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 27 01:09:38 PST 2017


On Sunday, 26 February 2017 at 21:50:38 UTC, Jordan Wilson wrote:
> auto readNumMatCsv2 (string filePath, string ndv, string 
> new_ndv){
>     double[][] p_numArray;
>     try {
>         auto lines = File(filePath,"r").byLine;
>         lines.popFront; // get read of header
>         p_numArray = lines.map!(a => a.replace (ndv,new_ndv)
>                                       .splitter (",")
>                                       .map!(a => a.to!double)
>                                       .array)
>                           .array;
>     } catch (Exception e){
>         e.msg.writeln; // this replaces "Could not read file. 
> Quit here."
>     }
>     return p_numArray;
> }
>
> It took me quite a while to get the whole usage of range stuff 
> like "map" and "filter" etc., but I think it's worth the effort.

This looks like more friendly readable compact code, where should 
be the goal. Thanks for your insights!



More information about the Digitalmars-d-learn mailing list