The OpenD Programming Language

triplets

Constructs a lazy view of triplets with left, center, and right members.

  1. Slice!(TripletIterator!(Iterator, kind)) triplets(Slice!(Iterator, 1, kind) slice)
    Slice!(TripletIterator!(Iterator, kind))
    triplets
    (
    Iterator
    SliceKind kind
    )
    (
    Slice!(Iterator, 1, kind) slice
    )
  2. Slice!(TripletIterator!(T*)) triplets(T[] slice)
  3. auto triplets(S slice, size_t n)

Parameters

slice Slice!(Iterator, 1, kind)

a slice or an array to iterate over

Return Value

Type: Slice!(TripletIterator!(Iterator, kind))

Slice of the same length composed of Triplet triplets. The center member is type of a slice element. The left and right members has the same type as slice.

The module contains special function collapse to handle left and right side of triplets in one expression.

Examples

triplets(eeeeee) =>

||c|lllll|
|r|c|llll|
|rr|c|lll|
|rrr|c|ll|
|rrrr|c|l|
|rrrrr|c||
import mir.ndslice.slice: sliced;
import mir.ndslice.topology: triplets, member, iota;

auto a = [4, 5, 2, 8];
auto h = a.triplets;

assert(h[1].center == 5);
assert(h[1].left == [4]);
assert(h[1].right == [2, 8]);

h[1].center = 9;
assert(a[1] == 9);

assert(h.member!"center" == a);

// `triplets` topology can be used with iota to index a slice
auto s = a.sliced;
auto w = s.length.iota.triplets[1];

assert(&s[w.center] == &a[1]);
assert(s[w.left].field is a[0 .. 1]);
assert(s[w.right].field is a[2 .. $]);

See Also

Meta