The OpenD Programming Language

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.

struct Transversal (
Ror
TransverseOptions opt = TransverseOptions.assumeJagged
) {}

Constructors

this
this(RangeOfRanges input, size_t n)

Construction from an input and an index.

Members

Functions

moveAt
E moveAt(size_t n)

Random-access primitive. It is offered if isRandomAccessRange!RangeOfRanges && (opt == TransverseOptions.assumeNotJagged || opt == TransverseOptions.enforceNotJagged).

moveBack
E moveBack()

Bidirectional primitives. They are offered if isBidirectionalRange!RangeOfRanges.

moveFront
E moveFront()

Forward range primitives.

opIndex
auto ref opIndex(size_t n)
opIndexAssign
void opIndexAssign(E val, size_t n)

Random-access primitive. It is offered if isRandomAccessRange!RangeOfRanges && (opt == TransverseOptions.assumeNotJagged || opt == TransverseOptions.enforceNotJagged).

opSlice
typeof(this) opSlice(size_t lower, size_t upper)

Slicing if offered if RangeOfRanges supports slicing and all the conditions for supporting indexing are met.

popBack
void popBack()

Bidirectional primitives. They are offered if isBidirectionalRange!RangeOfRanges.

popFront
void popFront()

Forward range primitives.

Properties

back
auto ref back [@property getter]
E back [@property setter]

Bidirectional primitives. They are offered if isBidirectionalRange!RangeOfRanges.

front
auto ref front [@property getter]
E front [@property setter]
save
typeof(this) save [@property getter]

Forward range primitives.

Variables

empty
enum bool empty;

Forward range primitives.

Parameters

opt

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

Return Value

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