Good name for f.byLine.map!(x => x.idup)?

Vladimir Panteleev vladimir at thecybershadow.net
Sun Mar 16 12:55:06 PDT 2014


On Sunday, 16 March 2014 at 18:14:18 UTC, Jakob Ovrum wrote:
> On Sunday, 16 March 2014 at 18:06:00 UTC, Vladimir Panteleev 
> wrote:
>> On Sunday, 16 March 2014 at 16:58:36 UTC, Andrei Alexandrescu 
>> wrote:
>>> A classic idiom for reading lines and keeping them is 
>>> f.byLine.map!(x => x.idup) to get strings instead of the 
>>> buffer etc.
>>>
>>> The current behavior trips new users on occasion, and the 
>>> idiom solving it is very frequent. So what the heck - let's 
>>> put that in a function, expose and document it nicely, and 
>>> call it a day.
>>>
>>> A good name would help a lot. Let's paint that bikeshed!
>>
>> For the record, if you want to keep all lines in memory 
>> anyway, it's more efficient to just read the whole file at 
>> once then split it with splitLines(), because you avoid doing 
>> one memory allocation per line. The downside is if you want to 
>> keep only some of the lines on the heap in a long-running 
>> program - with this approach, the slices pin the entire file 
>> content.
>
> Reading all at once is also a problem for really big files.

It is no different from:

f.byLine.map!(x => x.idup).array

...which is why I said "if you want to keep all lines in memory 
anyway".


More information about the Digitalmars-d mailing list