Thread overview | |||||
---|---|---|---|---|---|
|
February 25, 2018 Zip with range of ranges | ||||
---|---|---|---|---|
| ||||
Instead of passing std.range.zip a set of ranges as different arguments, is it possible to hand the m a range of ranges, and get them to zip together each element of every subrange? |
February 25, 2018 Re: Zip with range of ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to ARaspiK | On Sunday, 25 February 2018 at 16:22:19 UTC, ARaspiK wrote:
> Instead of passing std.range.zip a set of ranges as different arguments, is it possible to hand the m a range of ranges, and get them to zip together each element of every subrange?
`std.range.transposed` does this, but it requires that the range of ranges has assignable elements, so it may not work in all cases. For example:
import std.range;
import std.algorithm.iteration;
import std.stdio;
auto rr1 = [[1, 2, 3], [4, 5, 6]];
rr1.transposed.each!writeln; // Works
auto rr2 = only(only(1, 2, 3), only(4, 5, 6));
rr2.transposed.each!writeln; // Doesn't work
|
February 26, 2018 Re: Zip with range of ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Sunday, 25 February 2018 at 20:18:27 UTC, Paul Backus wrote:
> On Sunday, 25 February 2018 at 16:22:19 UTC, ARaspiK wrote:
>> Instead of passing std.range.zip a set of ranges as different arguments, is it possible to hand the m a range of ranges, and get them to zip together each element of every subrange?
>
> `std.range.transposed` does this, but it requires that the range of ranges has assignable elements, so it may not work in all cases. For example:
>
> import std.range;
> import std.algorithm.iteration;
> import std.stdio;
>
> auto rr1 = [[1, 2, 3], [4, 5, 6]];
> rr1.transposed.each!writeln; // Works
>
> auto rr2 = only(only(1, 2, 3), only(4, 5, 6));
> rr2.transposed.each!writeln; // Doesn't work
Thank you so much. It works now. I was already receiving a forward range, so copying was easy.
|
Copyright © 1999-2021 by the D Language Foundation