Why does std.string.splitLines return an array?

bearophile bearophileHUGS at lycos.com
Sun Oct 21 15:14:42 PDT 2012


Chad J:

> std.string.splitLines returns an array, which is pretty grody.  
> Why not return a lazily-evaluated range struct so that we can 
> avoid allocations on this simple but common operation?

splitLines is probably modeled on the str.splitlines() string 
method of Python, that returns a list (array) of strings (because 
originally Python was eager). In Phobos there is both a split() 
and splitter(), they are eager and lazy. So maybe you want a 
splitterLines().

I have asked for a lazy splitLines, vote here:
http://d.puremagic.com/issues/show_bug.cgi?id=4764

But I have suggested for a different naming:
http://d.puremagic.com/issues/show_bug.cgi?id=5838

See also:
http://d.puremagic.com/issues/show_bug.cgi?id=6730
http://d.puremagic.com/issues/show_bug.cgi?id=7689

And especially:
http://d.puremagic.com/issues/show_bug.cgi?id=8013

Bye,
bearophile


More information about the Digitalmars-d mailing list