On Monday, 22 July 2013 at 23:28:46 UTC, Jonathan M Davis wrote:
On Monday, July 22, 2013 13:08:05 Nick Treleaven wrote:
Hi,
I remember an example in some slides by Walter which had this
snippet
(slightly simplified):
stdin.byLine.map!(l => l.idup).array
Someone commented in a reddit post that the idup part was not
intuitive
(can't find the link now, sorry).
I made a pull request to re-enable using byLine!(char,
immutable char).
(Note this compiled in the current release, but didn't work
properly
AFAICT. It did work by commit 97cec33^).
https://github.com/D-Programming-Language/phobos/pull/1418
Using that allows us to drop the map!(l => l.idup) part from
the above
snippet. The new syntax isn't much better, but it can also be
more
efficient (as it caches front). I have an idea how to improve
the
syntax, but I'll omit it for this post.
I agree with monarch in that we really shouldn't try and mess
with byLine like
this. It would just be cleaner to come up with a new function
for this, though
I confess that part of me thinks that it's better to just use
map!(a =>
a.idup)(), because it avoids duplicating functionality. It is
arguably a bit
ugly though.
It is also inefficient, if you pipe it to an algorithm that calls
the same front more than once, you'll end up duping more than
once. It could be mitigated with my proposed "cache" adaptor, but
then, we'd have:
file.byLine().map!(a => a.idup)().cache();
It works, but it is horrible to look at.
I'm rather in favor of a named "byDupLine", which is self
documenting, easy to use, and new/casual programmer friendly.