Good name for f.byLine.map!(x => x.idup)?
Meta
jared771 at gmail.com
Sun Mar 16 13:17:03 PDT 2014
On Sunday, 16 March 2014 at 17:49:56 UTC, bearophile wrote:
> Andrei Alexandrescu:
>
>> A classic idiom for reading lines and keeping them is
>> f.byLine.map!(x => x.idup) to get strings instead of the
>> buffer etc.
>
> This is essentially this issue, I will reopen it if you want:
> https://d.puremagic.com/issues/show_bug.cgi?id=4474
>
>
>> The current behavior trips new users on occasion,
>
> In D the default behaviors should be "not tripping". And the
> optimized behavour should be on explicit request.
>
> So I think byLine should dup on default, and it should not dup
> on request. As I explained in Issue 4474.
>
> Perhaps this breaking change (I asked in Issue 4474) in byLine
> can't happen now.
>
>
>> 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!
>
> A good function name for the copying version is:
>
> "byDupLines"
>
>
> An alternative solution is the opposite of that I was
> suggesting in Issue 4474:
>
> byLine => not dup
>
> byLine!true => copies every line with dup
>
> Bye,
> bearophile.
Can't it be as simple as adding a new overload for byLine?
auto byLine(Terminator = char, Char = char, Flag!"cacheLines"
cacheLines = Yes.cacheLines)(KeepTerminator keepTerminator =
KeepTerminator.no, Terminator terminator = '\x0a')
Otherwise, we should probably just merge MonarchDodra's cache
range adapter, and could even add a specialization for byLine's
ByLine struct.
More information about the Digitalmars-d
mailing list