View source code
Display the source code in std/range/package.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.range.Transversal/transversal - multiple declarations

Function 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(TransverseOptions opt = TransverseOptions.assumeJagged, RangeOfRanges) (
  RangeOfRanges rr,
  size_t n
);

Parameters

NameDescription
opt Controls the assumptions the function makes about the lengths of the ranges
rr An input range of random access ranges

Returns

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

Example

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 ]));

Example

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]]));

Struct 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

NameDescription
this Construction from an input and an index.

Properties

NameTypeDescription
back[get, set] autoBidirectional primitives. They are offered if isBidirectionalRange!RangeOfRanges.
front[get, set] autoForward range primitives.
length[get] size_tRandom-access primitive. It is offered if isRandomAccessRange!RangeOfRanges && (opt == TransverseOptions.assumeNotJagged || opt == TransverseOptions.enforceNotJagged).
save[get] typeof(this)Forward range primitives.

Methods

NameDescription
moveAt Random-access primitive. It is offered if isRandomAccessRange!RangeOfRanges && (opt == TransverseOptions.assumeNotJagged || opt == TransverseOptions.enforceNotJagged).
moveBack Bidirectional primitives. They are offered if isBidirectionalRange!RangeOfRanges.
moveFront Forward range primitives.
opIndex Random-access primitive. It is offered if isRandomAccessRange!RangeOfRanges && (opt == TransverseOptions.assumeNotJagged || opt == TransverseOptions.enforceNotJagged).
opIndexAssign Random-access primitive. It is offered if isRandomAccessRange!RangeOfRanges && (opt == TransverseOptions.assumeNotJagged || opt == TransverseOptions.enforceNotJagged).
opSlice Slicing if offered if RangeOfRanges supports slicing and all the conditions for supporting indexing are met.
popBack Bidirectional primitives. They are offered if isBidirectionalRange!RangeOfRanges.
popFront Forward range primitives.

Aliases

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

Parameters

NameDescription
opt Controls the assumptions the function makes about the lengths of the ranges
rr An input range of random access ranges

Returns

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

Example

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 ]));

Example

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]]));

Authors

Andrei Alexandrescu, David Simcha, Jonathan M Davis, and Jack Stouffer. Credit for some of the ideas in building this module goes to Leonardo Maffi.

License

Boost License 1.0.