http://d.puremagic.com/issues/show_bug.cgi?id=4468

           Summary: std.string.join() for lazy iterable of strings
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2010-07-15 17:24:25 PDT ---
This Python code generates a lazy sequence of the first 20 integers (starting
from 0), then maps them lazily to strings, and then joins them in a single
string:


from itertools import imap
r = imap(str, xrange(20))
result = "".join(r)
print result



The same code can be written in D2:

import std.stdio, std.algorithm, std.conv, std.range, std.string;
void main() {
    auto r = map!("to!string(a)")(iota(20));
    //string result = join(array(r), ""); // OK
    string result = join(r, ""); // error
    writeln(result);
}


But I'd like a std.string.join() able to accept a Range too, so I can use
join(r, "") instead of join(array(r), ""), because it's shorter, simpler,
natural enough and reduces memory used (and probably increases code performance
too).

When the total size of the resulting string is not known because the input is a
lazy sequence of strings, then probably join() has to use something like
appender() to improve its performance.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to