Zip with range of ranges

Paul Backus snarwin at gmail.com
Sun Feb 25 20:18:27 UTC 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


More information about the Digitalmars-d-learn mailing list