digitalmars.D - Interest in std.algorithm.joiner?
- Andrei Alexandrescu (6/6) Jul 27 2010 We have std.algorithm.splitter which splits a range into components
- dsimcha (6/12) Jul 27 2010 Absolutely. I was thinking a while back I was going to suggest a
- bearophile (5/8) Jul 27 2010 That's a chain() not a flattener() :-)
- bearophile (9/14) Jul 27 2010 In Python (and D) a commonly useful function is split() that splits a st...
- Jonathan M Davis (8/17) Jul 27 2010 Well, I don't think that I can currently say that I've written an app th...
- Steven Schveighoffer (4/9) Jul 27 2010 How do you do that?
- Andrei Alexandrescu (4/15) Jul 27 2010 Well joiner would offer an input or in best case a forward range with
- Steven Schveighoffer (7/20) Jul 27 2010 How do you store all the ranges you joined for future reference without ...
- Andrei Alexandrescu (5/28) Jul 27 2010 It's just one range and one separator.
- Steven Schveighoffer (11/36) Jul 27 2010 Ah, Ok. I was under the impression that the input was a bunch of
- Andrei Alexandrescu (4/45) Jul 27 2010 As of the upcoming release, I changed write() and writeln() to fully
- sybrandy (2/6) Jul 27 2010 Looks good to me. I vote for having it.
- Rory Mcguire (2/34) Jul 29 2010 Not sure, but wouldn't it be better to call that unite?
- Philippe Sigaud (12/16) Jul 29 2010 Seeing your code in svn, wouldn't also a flatten() (or, concat() ) funct...
- dsimcha (3/24) Jul 27 2010 I was under the impression that the idea is that you'd have a range of r...
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
Jul 27 2010
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail erdani.org)'s articleWe 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? AndreiAbsolutely. 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.
Jul 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
Jul 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
Jul 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? AndreiWell, 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
Jul 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
Jul 27 2010
Steven Schveighoffer wrote:On Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Well joiner would offer an input or in best case a forward range with the range primitives. AndreiWe 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?
Jul 27 2010
On Tue, 27 Jul 2010 14:12:34 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Steven Schveighoffer wrote: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? -SteveOn Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Well joiner would offer an input or in best case a forward range with the range primitives.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?
Jul 27 2010
Steven Schveighoffer wrote:On Tue, 27 Jul 2010 14:12:34 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:It's just one range and one separator. auto joined = joiner(["Mary", "has"], "\t"); assert(joined.front == 'M'); AndreiSteven Schveighoffer wrote: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?On Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Well joiner would offer an input or in best case a forward range with the range primitives.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?
Jul 27 2010
On Tue, 27 Jul 2010 14:27:20 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Steven Schveighoffer wrote: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? -SteveOn Tue, 27 Jul 2010 14:12:34 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:It's just one range and one separator. auto joined = joiner(["Mary", "has"], "\t"); assert(joined.front == 'M');Steven Schveighoffer wrote: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?On Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Well joiner would offer an input or in best case a forward range with the range primitives.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?
Jul 27 2010
Steven Schveighoffer wrote:On Tue, 27 Jul 2010 14:27:20 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:As of the upcoming release, I changed write() and writeln() to fully support input ranges. AndreiSteven Schveighoffer wrote: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?On Tue, 27 Jul 2010 14:12:34 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:It's just one range and one separator. auto joined = joiner(["Mary", "has"], "\t"); assert(joined.front == 'M');Steven Schveighoffer wrote: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?On Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Well joiner would offer an input or in best case a forward range with the range primitives.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?
Jul 27 2010
It's just one range and one separator. auto joined = joiner(["Mary", "has"], "\t"); assert(joined.front == 'M'); AndreiLooks good to me. I vote for having it. Casey
Jul 27 2010
Andrei Alexandrescu wrote:Steven Schveighoffer wrote:Not sure, but wouldn't it be better to call that unite?On Tue, 27 Jul 2010 14:12:34 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:It's just one range and one separator. auto joined = joiner(["Mary", "has"], "\t"); assert(joined.front == 'M'); AndreiSteven Schveighoffer wrote: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?On Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Well joiner would offer an input or in best case a forward range with the range primitives.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?
Jul 29 2010
Andrei Alexandrescu wrote: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. PhilippeIs 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?
Jul 29 2010
== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articleOn Tue, 27 Jul 2010 14:12:34 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:I was under the impression that the idea is that you'd have a range of ranges, for example an array of strings.Steven Schveighoffer wrote: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? -SteveOn Tue, 27 Jul 2010 11:21:08 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Well joiner would offer an input or in best case a forward range with the range primitives.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?
Jul 27 2010