Thread overview |
---|
September 23, 2015 Is there a smart way to process a range of range by front ? | ||||
---|---|---|---|---|
| ||||
I was thinking to a general *interleave()* algorithm for any compatible Range of Range but I can't find any smart way to process each sub range by front, eg: --- void interleave(RoR)(RoR r) { r.each!(a => a.writeln); } void main() { auto r = [[0,2],[1,3]]; interleave(r); } --- will print: [0,2] [1,3] while to interleave i need to take the front of each sub range before poping each ror element. Currently I'm here (don't run this ;)) : --- auto interleave(RoR)(RoR r) { alias T = ElementType!r[0]; T[] result; while (!empty(r[0])) r.each!(a => (result ~= a.front, a.popFront)); return result; } void main() { auto r = [[0,2],[1,3]]; interleave(r); } --- but it doesn't work because 'a' is not consumed. It looks like it's saved from the input parameter at each iteration of the while loop hence it never returns. Is it possible ? |
September 23, 2015 Re: Is there a smart way to process a range of range by front ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BBasile | On Wednesday, 23 September 2015 at 20:44:07 UTC, BBasile wrote:
> Is it possible ?
sorry, I meant to post this in .learn
|
September 24, 2015 Re: Is there a smart way to process a range of range by front ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BBasile | On Wednesday, 23 September 2015 at 20:44:07 UTC, BBasile wrote: > I was thinking to a general *interleave()* algorithm for any compatible Range of Range but I can't find any smart way to process each sub range by front, eg: > Is it possible ? What exactly shall your function do? How is it different from http://dlang.org/phobos/std_range.html#.transposed and http://dlang.org/phobos/std_range.html#roundRobin ? |
September 24, 2015 Re: Is there a smart way to process a range of range by front ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to thedeemon | On Thursday, 24 September 2015 at 04:26:05 UTC, thedeemon wrote: > On Wednesday, 23 September 2015 at 20:44:07 UTC, BBasile wrote: >> I was thinking to a general *interleave()* algorithm for any compatible Range of Range but I can't find any smart way to process each sub range by front, eg: >> Is it possible ? > > What exactly shall your function do? How is it different from > http://dlang.org/phobos/std_range.html#.transposed > and > http://dlang.org/phobos/std_range.html#roundRobin > ? http://forum.dlang.org/thread/lwehxuaarulmyiquoqsu@forum.dlang.org problem solved (transposed.joiner) [1]. If someone cleans the NG server some time to time this topic should be marked for. |
Copyright © 1999-2021 by the D Language Foundation