A range is a well-defined sequence of elements that are part of a collection.

Traversing a range that is being mutated results is undefined behavior (with some exceptions). To be safe, you need to manually make a copy of the elements in the range before adding or removing elements.

interface Range<T> {
    reversed?: boolean;
    size: number;
    "[iterator]"(): IterableIterator<T, any, any>;
    cursors(): IterableIterator<Cursor<T>, any, any>;
    filter(pred: (element: Cursor<T>) => boolean): Range<T>;
    reverse(): Range<T>;
}

Type Parameters

  • T

Properties

reversed?: boolean

Indicates whether this range will traverse its elements in reverse order.

size: number

Get how many elements are in this range.

⚠️ This might be an expensive operation, so make sure to cache it if you need frequent access to it.

Methods

  • Get an iterator that sequences the elements contained in this range.

    Returns IterableIterator<T, any, any>

  • Return an iterator that provides cursors to inspect or delete the given element.

    Returns IterableIterator<Cursor<T>, any, any>

    Cursor

  • Filters this range using the given predicate. Iterating over the newly returned range will cause all cursors that did not match the predicate to be omitted.

    Parameters

    • pred: (element: Cursor<T>) => boolean

    Returns Range<T>

  • Reverse the order of the elements that would be generated with the iterator.

    Reversing a range is only possible when the order of the elements is well-defined, such as the elements in a list or a tree-based dictionary.

    Returns Range<T>