std.range.Transversal/transversal
- multiple declarations
Function transversal
Given a range of ranges, iterate transversally through the
n
th 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
Name | Description |
---|---|
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
n
th element of each of the enclosed ranges. This function
is similar to unzip
in other languages.
Constructors
Name | Description |
---|---|
this
(input, n)
|
Construction from an input and an index. |
Properties
Name | Type | Description |
---|---|---|
back [get, set]
|
auto | Bidirectional primitives. They are offered if isBidirectionalRange!RangeOfRanges .
|
front [get, set]
|
auto | Forward range primitives. |
save [get]
|
typeof(this) | Forward range primitives. |
Methods
Name | Description |
---|---|
moveAt
(n)
|
Random-access primitive. It is offered if isRandomAccessRange!RangeOfRanges && (opt ==
TransverseOptions .
|
moveBack
()
|
Bidirectional primitives. They are offered if isBidirectionalRange!RangeOfRanges .
|
moveFront
()
|
Forward range primitives. |
opIndex
(n)
|
Random-access primitive. It is offered if isRandomAccessRange!RangeOfRanges && (opt ==
TransverseOptions .
|
opIndexAssign
(val, n)
|
Random-access primitive. It is offered if isRandomAccessRange!RangeOfRanges && (opt ==
TransverseOptions .
|
opSlice
(lower, upper)
|
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. |
Parameters
Name | Description |
---|---|
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.