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

--- Comment #0 from 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

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

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

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:
------- You are receiving this mail because: -------

Reply via email to