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

> 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');

Ah, Ok.  I was under the impression that the input was a bunch of individual ranges to join.

So basically, you are pushing the "range of ranges" allocation onto the user.  That works.

That is quite an interesting problem, esp if you intend to keep it lazy and forward things like random access to the joined range.  Or output the result to writeln.  Hey, could it potentially be used as a formatter to writefln?

-Steve
July 27, 2010
Steven Schveighoffer wrote:
> On Tue, 27 Jul 2010 14:27:20 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> 
>> 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');
> 
> Ah, Ok.  I was under the impression that the input was a bunch of individual ranges to join.
> 
> So basically, you are pushing the "range of ranges" allocation onto the user.  That works.
> 
> That is quite an interesting problem, esp if you intend to keep it lazy and forward things like random access to the joined range.  Or output the result to writeln.  Hey, could it potentially be used as a formatter to writefln?

As of the upcoming release, I changed write() and writeln() to fully support input ranges.

Andrei
July 27, 2010
> It's just one range and one separator.
>
> auto joined = joiner(["Mary", "has"], "\t");
> assert(joined.front == 'M');
>
>
> Andrei

Looks good to me.  I vote for having it.

Casey
July 29, 2010
Andrei Alexandrescu wrote:

> 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

Not sure, but wouldn't it be better to call that unite?

July 29, 2010
>
> Andrei Alexandrescu wrote:
> >>>>> 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?
>

Seeing your code in svn, wouldn't also a flatten() (or, concat() ) function
be interesting? It transforms a range of ranges (of whatever depth) into a
linear range.

Also, interpose(range, element) that returns range[0], element, range[1],
element, etc.
and interleave(range1, range2) that produces range1[0], range2[0],
range1[1], range2[1], range1[2], ...

Isn't joiner just chain(interpose(["Mary", "has", "a", "little", "lamb"],
"...")?

std.range.transversal is a bit... short on this one: it just iterates through a 'vertical' slice.



Philippe


Next ›   Last »
1 2
Top | Discussion index | About this forum | D home