radial

Iterates a random-access range starting from a given point and progressively extending left and right from that point. If no initial point is given, iteration starts from the middle of the range. Iteration spans the entire range.

When startingIndex is 0 the range will be fully iterated in order and in reverse order when r.length is given.

  1. auto radial(Range r, I startingIndex)
    radial
    (
    Range
    I
    )
    (
    Range r
    ,)
    if (
    isRandomAccessRange!(Unqual!Range) &&
    hasLength!(Unqual!Range)
    &&
    hasSlicing!(Unqual!Range)
    &&
    )
  2. auto radial(R r)

Parameters

r Range

a random access range with length and slicing

startingIndex I

the index to begin iteration from

Return Value

Type: auto

A forward range with length

Examples

import std.algorithm.comparison : equal;
int[] a = [ 1, 2, 3, 4, 5 ];
assert(equal(radial(a), [ 3, 4, 2, 5, 1 ]));
a = [ 1, 2, 3, 4 ];
assert(equal(radial(a), [ 2, 3, 1, 4 ]));

// If the left end is reached first, the remaining elements on the right
// are concatenated in order:
a = [ 0, 1, 2, 3, 4, 5 ];
assert(equal(radial(a, 1), [ 1, 2, 0, 3, 4, 5 ]));

// If the right end is reached first, the remaining elements on the left
// are concatenated in reverse order:
assert(equal(radial(a, 4), [ 4, 5, 3, 2, 1, 0 ]));

Meta