Interest in std.algorithm.joiner?
bearophile
bearophileHUGS at lycos.com
Tue Jul 27 09:56:02 PDT 2010
Andrei Alexandrescu:
> We have std.algorithm.splitter which splits a range into components
> without allocating a new array.
In Python (and D) a commonly useful function is split() that splits a string according to whitespace, and split(str) that splits it according to a string. There is a similar function in std.string.
Then Python misses a lot a function that does the same of split/split(str) but yields its results lazily, this can save a large amount of memory if the string to split is very large.
Such split/xsplit (or splitter) are very useful for arrays too, and generic ranges (lazy too).
> Is there an interest in joiner(), the corresponding function for join()
> that joins elements of a range in conjunction with a separator without
> allocating a new array?
A join, that does the opposite of split is very useful, especially if strings are an immutable data type (and it's useful for other arrays too, etc).
Is your joiner like chain(), that is it gives a lazy iterable as chain(), but also contains the separator?
A join when used on strings is often used to build a string that later is stored somewhere or often printed. If your printing functions accept lazy sequences of strings too, for example given by joiner, then I think joiner() can be useful. For generic arrays I can't see immediate usages.
Bye,
bearophile
More information about the Digitalmars-d
mailing list