Jump to page: 1 2
Thread overview
Interest in std.algorithm.joiner?
Jul 27, 2010
dsimcha
Jul 27, 2010
bearophile
Jul 27, 2010
bearophile
Jul 27, 2010
Jonathan M Davis
Jul 27, 2010
sybrandy
Jul 29, 2010
Rory Mcguire
Jul 29, 2010
Philippe Sigaud
Jul 27, 2010
dsimcha
July 27, 2010
We have std.algorithm.splitter which splits a range into components without allocating a new array.

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?


Andrei
July 27, 2010
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s article
> We have std.algorithm.splitter which splits a range into components
> without allocating a new array.
> 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?
> Andrei

Absolutely.  I was thinking a while back I was going to suggest a std.range.flattener() or std.algorithm.flattener() that takes a range of ranges and turns them into a single range, one right after the other.  joiner() would be a generalization of this in that to flatten a ror, you'd just join it on an empty range.
July 27, 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
July 27, 2010
dsimcha:
> Absolutely.  I was thinking a while back I was going to suggest a std.range.flattener() or std.algorithm.flattener() that takes a range of ranges and turns them into a single range, one right after the other.

That's a chain() not a flattener() :-)
A flatten operation is usually meant when you have a tree (sometimes even a tree of arbitrary and dis-uniform depth) of iterables and you want to fully linearise it.

Bye,
bearophile
July 27, 2010
On Tuesday, July 27, 2010 08:21:08 Andrei Alexandrescu wrote:
> We have std.algorithm.splitter which splits a range into components without allocating a new array.
> 
> 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?
> 
> 
> Andrei

Well, I don't think that I can currently say that I've written an app that would have liked to have joiner(), but I've definitely used join() often enough. However, I'd argue that it would be good to add it for completeness' sake, if nothing else. And it wouldn't surprise me at all to end up writing an app one of these days that found joiner() to be quite useful. I certainly can't think of any reason for _not_ having it.

- Jonathan M Davis
July 27, 2010
On Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:

> We have std.algorithm.splitter which splits a range into components without allocating a new array.
>
> 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?

How do you do that?

-Steve
July 27, 2010
Steven Schveighoffer wrote:
> On Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> 
>> We have std.algorithm.splitter which splits a range into components without allocating a new array.
>>
>> 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?
> 
> How do you do that?

Well joiner would offer an input or in best case a forward range with the range primitives.

Andrei
July 27, 2010
On Tue, 27 Jul 2010 14:12:34 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:

> Steven Schveighoffer wrote:
>> On Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
>>
>>> We have std.algorithm.splitter which splits a range into components without allocating a new array.
>>>
>>> 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?
>>  How do you do that?
>
> Well joiner would offer an input or in best case a forward range with the range primitives.

How do you store all the ranges you joined for future reference without creating an array of those ranges?  With splitter, it's straightforward, there's one range to store.

Or am I missing something?

-Steve
July 27, 2010
Steven Schveighoffer wrote:
> On Tue, 27 Jul 2010 14:12:34 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> 
>> Steven Schveighoffer wrote:
>>> On Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
>>>
>>>> We have std.algorithm.splitter which splits a range into components without allocating a new array.
>>>>
>>>> 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?
>>>  How do you do that?
>>
>> Well joiner would offer an input or in best case a forward range with the range primitives.
> 
> How do you store all the ranges you joined for future reference without creating an array of those ranges?  With splitter, it's straightforward, there's one range to store.
> 
> Or am I missing something?

It's just one range and one separator.

auto joined = joiner(["Mary", "has"], "\t");
assert(joined.front == 'M');


Andrei
July 27, 2010
== Quote from Steven Schveighoffer (schveiguy@yahoo.com)'s article
> On Tue, 27 Jul 2010 14:12:34 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> > Steven Schveighoffer wrote:
> >> On Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> >>
> >>> We have std.algorithm.splitter which splits a range into components without allocating a new array.
> >>>
> >>> 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?
> >>  How do you do that?
> >
> > Well joiner would offer an input or in best case a forward range with the range primitives.
> How do you store all the ranges you joined for future reference without
> creating an array of those ranges?  With splitter, it's straightforward,
> there's one range to store.
> Or am I missing something?
> -Steve

I was under the impression that the idea is that you'd have a range of ranges, for example an array of strings.
« First   ‹ Prev
1 2