Basic module

array_view

procedure2 overloadsSource

A view of the elements of array from index on, or of count of them from index.

The view shares the array's memory, so writes through it change the array, and it is only good while the array is not freed or grown. It is clamped, not an error, to run past the end: a count that is too large is cut short, and an index at or beyond the end gives an empty view. A negative index or count fails an assert.

Example↗
values := int.[1, 2, 3, 4, 5];
middle := array_view(values, 1, 3);
assert(middle.count == 3 && middle[0] == 2);

tail := array_view(values, 3);
assert(tail.count == 2 && tail[1] == 5);

middle[0] = 20; // writes into `values`
assert(values[1] == 20);
assert(array_view(values, 9).count == 0);
array_view :: (array: [] $T, index: int) -> [] T

Parameters

array: [] $T
index: int

Returns

[] T
array_view :: (array: [] $T, index: int, count: int) -> [] T

At most count elements from index; see the first array_view for the clamping rules.

Parameters

array: [] $T
index: int
count: int

Returns

[] T
Example↗
values := int.[1, 2, 3, 4];
assert(array_view(values, 1, 2).count == 2);

See also