transversal

Given a range of ranges, iterate transversally through the nth element of each of the enclosed ranges. This function is similar to unzip in other languages.

Transversal!(RangeOfRanges, opt)
transversal
(
RangeOfRanges rr
,
size_t n
)

Parameters

opt

Controls the assumptions the function makes about the lengths of the ranges

rr RangeOfRanges

An input range of random access ranges

Return Value

Type: Transversal!(RangeOfRanges, opt)

At minimum, an input range. Range primitives such as bidirectionality and random access are given if the element type of rr provides them.

Examples

import std.algorithm.comparison : equal;
int[][] x = new int[][2];
x[0] = [1, 2];
x[1] = [3, 4];
auto ror = transversal(x, 1);
assert(equal(ror, [ 2, 4 ]));

The following code does a full unzip

import std.algorithm.comparison : equal;
import std.algorithm.iteration : map;
int[][] y = [[1, 2, 3], [4, 5, 6]];
auto z = y.front.walkLength.iota.map!(i => transversal(y, i));
assert(equal!equal(z, [[1, 4], [2, 5], [3, 6]]));

Meta