Thread overview
Zip with range of ranges
Feb 25, 2018
ARaspiK
Feb 25, 2018
Paul Backus
Feb 26, 2018
ARaspiK
February 25, 2018
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
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
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.