A standard doubly-linked list implementation.

Type Parameters

  • T

Implements

  • Iterable<T>

Constructors

Accessors

  • get empty(): boolean
  • Returns true if the list is empty.

    Returns boolean

  • get head(): null | LinkedNode<T>
  • Returns the current head.

    Returns null | LinkedNode<T>

  • get tail(): null | LinkedNode<T>
  • Returns the current tail.

    Returns null | LinkedNode<T>

Methods

  • Returns a new iterator, starting at the head.

    Returns IterableIterator<T>

  • Clears this list.

    Returns void

  • Creates an iterable iterator, starting at the specified node, getting the next node from the next() function.

    Note that using iterators is not as performant as some or forEach

    Parameters

    Returns {
        next: (() => IteratorResult<T, any>);
        [iterator](): IterableIterator<T>;
    }

    • next: (() => IteratorResult<T, any>)
        • (): IteratorResult<T, any>
        • Returns IteratorResult<T, any>

    • [iterator]:function
      • Returns IterableIterator<T>

  • Returns the first node matching the given predicate.

    Parameters

    • predicate: ((element: T) => boolean)

      A function where, when true is returned, returns the current node.

        • (element): boolean
        • Parameters

          • element: T

          Returns boolean

    Returns null | LinkedNode<T>

  • Returns the last node matching the given predicate.

    Parameters

    • predicate: ((element: T) => boolean)

      A function where, when true is returned, returns the current node.

        • (element): boolean
        • Parameters

          • element: T

          Returns boolean

    Returns null | LinkedNode<T>

  • Iterates over every element, invoking the given callback.

    Parameters

    • callback: ((element: T) => void)
        • (element): void
        • Parameters

          • element: T

          Returns void

    Returns void

  • Inserts the given node after pointer node.

    Parameters

    • node: LinkedNode<T>

      The node to insert after pointer. If this node is currently in this list, it will first be removed.

    • pointer: LinkedNode<T>

      The pointer node.

    Returns void

  • Inserts the given node before pointer node.

    Parameters

    • node: LinkedNode<T>

      The node to insert before pointer. If this node is currently in this list, it will first be removed.

    • pointer: LinkedNode<T>

      The pointer node.

    Returns void

  • Removes the last node (the tail), returning it. If this list is empty, null is returned.

    Returns null | LinkedNode<T>

  • Creates a new node for the given value, adding it to the end of the list.

    Parameters

    • value: T

    Returns LinkedNode<T>

    Returns the newly created node.

  • Appends all given values to the end of this list.

    Parameters

    • Rest...values: T[]

    Returns void

  • Appends the given node to the tail of this list. If the node is already at the tail, it will no-op. If the node is in this list, it will be removed.

    Parameters

    • node: LinkedNode<T>

      The node to add or move to the tail of this list.

    Returns void

  • Removes the given linked node.

    Parameters

    Returns void

  • Returns a new reversed iterable where the iterator starts at the tail, moving backwards to the head.

    Returns IterableIterator<T>

  • Removes the first node (the head), returning it.

    • If this list is empty, null is returned.

    Returns null | LinkedNode<T>

  • Similar to Array.prototype.some, returns true if at least one element passes the given predicate.

    Parameters

    • predicate: ((element: T) => boolean)
        • (element): boolean
        • Parameters

          • element: T

          Returns boolean

    Returns boolean

  • Creates a new node, adding it to the front of the list.

    Parameters

    • value: T

      The value to box in a linked node.

    Returns LinkedNode<T>

    Returns the new node.

  • Prepends all the given values to the head of this list. The values will maintain their order.

    E.g.

    list.unshiftAll(8, 9, 10)   // 8, 9, 10
    list.unshiftAll(4, 5, 6, 7) // 4, 5, 6, 7, 8, 9, 10
    list.unshiftAll(1, 2, 3) // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

    Parameters

    • Rest...values: T[]

      The values to box in linked nodes.

    Returns void

  • Prepends the given node to the head of this list.

    • If the node is already at the head, it will no-op.
    • If the node is in this list, it will be removed.

    Parameters

    • node: LinkedNode<T>

      The node to add or move to the head of this list.

    Returns void