Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents any collection that has an order defined on its elements.

Type parameters

  • T

Hierarchy

Implemented by

Index

Properties

Readonly size

size: number

Count the amount of elements in the collection.

⚠️ In most cases, this should be an O(1) operation. However, there are cases where this can be an O(n) operation. Therefore, it is recommended to always cache the result in a local variable.

Methods

[Symbol.iterator]

  • [Symbol.iterator](): IterableIterator<T>
  • Returns an object which is able to sift through the values in this collection.

    The order by which the elements are traversed depends on the kind of collection. For unordered collections, the iteration order is unspecified and may even differ between two iterations on the same collection.

    Returns IterableIterator<T>

add

  • Add an element to the collection. If the element already exists, update its value.

    The location where the element is placed depends on the collection type, and in the generic case there is no guarantee on the location where it is inserted.

    This method returns a pair with the first element indicating whether the element was added, while the second element refers to the actual location of the element.

    Parameters

    • element: T
    • Optional hint: any

      A transparent object obtained by getAddHint.

    Returns AddResult<T>

append

  • Append an item at the end of the collection. The element will be given the highest order.

    Parameters

    • el: T

    Returns Cursor<T>

at

  • at(position: number): Cursor<T>
  • Return a cursor that is placed at the index given by position in the sequence.

    Parameters

    • position: number

    Returns Cursor<T>

clear

  • clear(): void
  • Remove all elements from this collection, effectively setting the collection to the empty collection.

    Returns void

clone

delete

  • delete(element: T): boolean
  • Remove an element from the collection. If multiple elements are matched, the collection picks one of them.

    Parameters

    • element: T

    Returns boolean

    true if the element was found, false otherwise.

deleteAll

  • deleteAll(element: T): number
  • Remove an element from the collection. If multiple elements are matched, the collection removes all of them.

    Parameters

    • element: T

    Returns number

    The amount of elements that was removed.

deleteAt

  • deleteAt(position: Cursor<T>): void

first

  • first(): T
  • Get the first element in the sequence.

    throws

    An error object if the collection is empty.

    Returns T

Optional getAddHint

  • getAddHint(element: T): any
  • Returns a transparent object that can be used as an argument to add to speed up things. Generally, you don't have to use this method.

    Parameters

    • element: T

    Returns any

getAt

  • getAt(position: number): T
  • Allows taking an element directly out of the collection at a given position.

    This method might be faster than at because it is not forced to construct a cursor object.

    Parameters

    • position: number

    Returns T

has

  • has(element: T): boolean
  • Checks if the collection holds the given element.

    Parameters

    • element: T

      The element to check membership of.

    Returns boolean

    True if the collections holds the given element, false otherwise.

insertAfter

  • Insert an element after the element at the given position. The position is deduced from the iterator that is given to the method.

    Parameters

    Returns Cursor<T>

insertBefore

  • Insert an element before the element at the given position. The position is deduced from the iterator that is goven to the method.

    Parameters

    Returns Cursor<T>

Optional iterator

  • iterator(): Iterator<T, any, undefined>

last

  • last(): T
  • Get the last element in the collection.

    throws

    An error object if the collection is empty.

    Returns T

prepend

  • Prepend an item to the beginning of the collection. The element will be given the lowest order.

    Parameters

    • el: T

    Returns Cursor<T>

toRange

Legend

  • Property
  • Method
  • Accessor
  • Property
  • Method
  • Inherited property
  • Inherited method

Generated using TypeDoc