LinkedList Class
Package: @esfx/collections-linkedlist
A collection representing a [doubly-linked list](https://en.wikipedia.org/wiki/Doubly_linked_list).
Declaration
export declare class LinkedList<T> implements Collection<T>
Constructors
constructor(equaler)
Constructs a new instance of the LinkedList
class
Declaration
constructor(equaler?: EqualityComparison<T> | Equaler<T>);
Parameters
- equaler
- EqualityComparison<T> | Equaler<T>
constructor(iterable, equaler)
Constructs a new instance of the LinkedList
class
Declaration
constructor(iterable?: Iterable<T>, equaler?: EqualityComparison<T> | Equaler<T>);
Parameters
- iterable
- Iterable<T>
- equaler
- EqualityComparison<T> | Equaler<T>
Properties
[ReadonlyCollection.size]
Declaration
get [ReadonlyCollection.size](): number;
Property Value
[Symbol.toStringTag]
Declaration
[Symbol.toStringTag]: string;
Property Value
equaler
Gets the Equaler<T> used for equality comparisons in this list.
Declaration
get equaler(): Equaler<T>;
Property Value
first
Gets the first node in the list. If the list is empty, this returns undefined
.
Declaration
get first(): LinkedListNode<T> | undefined;
Property Value
last
Gets the last node in the list. If the list is empty, this returns undefined
.
Declaration
get last(): LinkedListNode<T> | undefined;
Property Value
size
Gets the number of elements in the list.
Declaration
get size(): number;
Property Value
Methods
[Collection.add](value)
Declaration
[Collection.add](value: T): void;
Parameters
- value
- T
Returns
[Collection.clear]()
Declaration
[Collection.clear](): void;
Returns
[Collection.delete](value)
Declaration
[Collection.delete](value: T): boolean;
Parameters
- value
- T
Returns
[ReadonlyCollection.has](value)
Declaration
[ReadonlyCollection.has](value: T): boolean;
Parameters
- value
- T
Returns
[Symbol.iterator]()
Declaration
[Symbol.iterator](): IterableIterator<T>;
Returns
clear()
Removes all nodes from the list.
Declaration
clear(): void;
Returns
delete(value)
Finds the first node in the list containing value
, removes it from the list, and returns it. If a node
containing value
could not be found, undefined
is returned instead.
Declaration
delete(value: T): LinkedListNode<T> | undefined;
Parameters
- value
- T
Returns
deleteAll(predicate, thisArg)
Removes all nodes from the list matching the supplied predicate
.
Declaration
deleteAll(predicate: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean, thisArg?: any): number;
Parameters
- predicate
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean
A callback function used to test each value and node in the list.
- thisArg
- any
The this
value to use when executing predicate
.
Returns
deleteNode(node)
Removes the provided node from the list.
Declaration
deleteNode(node: LinkedListNode<T> | null | undefined): boolean;
Parameters
- node
- LinkedListNode<T> | null | undefined
Returns
true
if the node was successfully removed from the list; otherwise, false
.
drain()
Returns an iterator that removes each node from the list before yielding the node's value.
Declaration
drain(): IterableIterator<T>;
Returns
every(callback, thisArg)
Declaration
every(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean, thisArg?: any): boolean;
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean
- thisArg
- any
Returns
filter(callback, thisArg)
Returns the elements of a the list that meet the condition specified in the provided callback
function.
Declaration
filter<S extends T>(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => value is S, thisArg?: any): LinkedList<S>;
Type Parameters
- S
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => value is S
The callback
to call for each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
filter(callback, thisArg)
Returns the elements of a the list that meet the condition specified in the provided callback
function.
Declaration
filter(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean, thisArg?: any): LinkedList<T>;
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean
The callback
to call for each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
find(callback, thisArg)
Finds the first value in the list that matches the provided callback.
Declaration
find<S extends T>(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => value is S, thisArg?: any): S | undefined;
Type Parameters
- S
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => value is S
The callback used to test each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
find(callback, thisArg)
Finds the first value in the list that matches the provided callback.
Declaration
find(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean, thisArg?: any): T | undefined;
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean
The callback used to test each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
findLast(callback, thisArg)
Finds the last value in the list that matches the provided callback, starting from the end of the list.
Declaration
findLast<S extends T>(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => value is S, thisArg?: any): S | undefined;
Type Parameters
- S
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => value is S
The callback used to test each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
findLast(callback, thisArg)
Finds the last value in the list that matches the provided callback, starting from the end of the list.
Declaration
findLast(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean, thisArg?: any): T | undefined;
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean
The callback used to test each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
findLastNode(callback, thisArg)
Finds the last LinkedListNode in the list that matches the provided callback, starting from the end of the list.
Declaration
findLastNode<S extends T>(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => value is S, thisArg?: any): LinkedListNode<S> | undefined;
Type Parameters
- S
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => value is S
The callback used to test each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
findLastNode(callback, thisArg)
Finds the last LinkedListNode in the list that matches the provided callback, starting from the end of the list.
Declaration
findLastNode(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean, thisArg?: any): LinkedListNode<T> | undefined;
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean
The callback used to test each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
findNode(callback, thisArg)
Finds the first LinkedListNode in the list that matches the provided callback.
Declaration
findNode<S extends T>(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => value is S, thisArg?: any): LinkedListNode<S> | undefined;
Type Parameters
- S
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => value is S
The callback used to test each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
findNode(callback, thisArg)
Finds the first LinkedListNode in the list that matches the provided callback.
Declaration
findNode(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean, thisArg?: any): LinkedListNode<T> | undefined;
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean
The callback used to test each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
forEach(callback, thisArg)
Declaration
forEach(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => void, thisArg?: any): void;
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => void
- thisArg
- any
Returns
has(value)
Returns a value indicating whether value
exists within the list.
Declaration
has(value: T): boolean;
Parameters
- value
- T
Returns
insertAfter(node, value)
Inserts a new LinkedListNode containing value
into the list after the provided node
.
If node
is either null
or undefined
, the new node is inserted at the end of the list.
Declaration
insertAfter(node: LinkedListNode<T> | null | undefined, value: T): LinkedListNode<T>;
Parameters
- value
- T
The value to insert.
Returns
The new LinkedListNode for value
.
insertBefore(node, value)
Inserts a new LinkedListNode containing value
into the list before the provided node
.
If node
is either null
or undefined
, the new node is inserted at the beginning of the list.
Declaration
insertBefore(node: LinkedListNode<T> | null | undefined, value: T): LinkedListNode<T>;
Parameters
- value
- T
The value to insert.
Returns
The new LinkedListNode for value
.
insertNodeAfter(node, newNode)
Inserts newNode
into the list after the provided node
. If node
is either null
or undefined
, newNode
is inserted at the end of the list.
Declaration
insertNodeAfter(node: LinkedListNode<T> | null | undefined, newNode: LinkedListNode<T>): void;
Parameters
Returns
insertNodeBefore(node, newNode)
Inserts newNode
into the list before the provided node
. If node
is either null
or undefined
, newNode
is inserted at the beginning of the list.
Declaration
insertNodeBefore(node: LinkedListNode<T> | null | undefined, newNode: LinkedListNode<T>): void;
Parameters
Returns
lastNodeOf(value, fromNode)
Finds the last node in the list with the provided value, starting from the end of the list.
Declaration
lastNodeOf(value: T, fromNode?: LinkedListNode<T> | null): LinkedListNode<T> | undefined;
Parameters
- value
- T
The value to find.
- fromNode
- LinkedListNode<T> | null
When provided, starts looking for value
starting at this node and working backwards towards the front of the list.
Returns
map(callback, thisArg)
Calls the provided callback
function on each element of the list, and returns a new LinkedList that contains the results.
Declaration
map<U>(callback: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => U, thisArg?: any): LinkedList<U>;
Type Parameters
- U
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => U
The callback to call for each value and node.
- thisArg
- any
The this
value to use when executing callback
.
Returns
nodeOf(value, fromNode)
Finds the first node in the list with the provided value.
Declaration
nodeOf(value: T, fromNode?: LinkedListNode<T> | null): LinkedListNode<T> | undefined;
Parameters
- value
- T
The value to find.
Returns
nodes()
Declaration
nodes(): IterableIterator<LinkedListNode<T>>;
Returns
pop()
Removes the last node from the list and returns its value. If the list is empty, undefined
is returned instead.
Declaration
pop(): T | undefined;
Returns
popNode()
Removes the last node from the list and returns it. If the lsit is empty, undefined
is returned instead.
Declaration
popNode(): LinkedListNode<T> | undefined;
Returns
push(value)
Inserts a new LinkedListNode containing value
at the end of the list.
Declaration
push(value: T): LinkedListNode<T>;
Parameters
- value
- T
The value to insert.
Returns
The new LinkedListNode for value
.
pushNode(newNode)
Inserts newNode
at the end of the list.
Declaration
pushNode(newNode: LinkedListNode<T>): void;
Parameters
Returns
reduce(callback)
Calls the specified callback
function for all the nodes in the list. The return value of the callback function is the accumulated result,
and is provided as an argument in the next call to the callback function.
Declaration
reduce(callback: (previousValue: T, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => T): T;
Parameters
- callback
- (previousValue: T, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => T
A function that accepts up to four arguments. The reduce method calls the callback function one time for each element in the list.
Returns
reduce(callback, initialValue)
Calls the specified callback
function for all the nodes in the list. The return value of the callback function is the accumulated result,
and is provided as an argument in the next call to the callback function.
Declaration
reduce(callback: (previousValue: T, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => T, initialValue: T): T;
Parameters
- callback
- (previousValue: T, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => T
A function that accepts up to four arguments. The reduce method calls the callback function one time for each element in the list.
- initialValue
- T
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callback
function provides this value as an argument instead of a list value.
Returns
reduce(callback, initialValue)
Calls the specified callback
function for all the nodes in the list. The return value of the callback function is the accumulated result,
and is provided as an argument in the next call to the callback function.
Declaration
reduce<U>(callback: (previousValue: U, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => U, initialValue: U): U;
Type Parameters
- U
Parameters
- callback
- (previousValue: U, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => U
A function that accepts up to four arguments. The reduce method calls the callback function one time for each element in the list.
- initialValue
- U
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callback
function provides this value as an argument instead of a list value.
Returns
reduceRight(callback)
Calls the specified callback
function for all the nodes in the list, in reverse. The return value of the callback function is the accumulated result,
and is provided as an argument in the next call to the callback function.
Declaration
reduceRight(callback: (previousValue: T, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => T): T;
Parameters
- callback
- (previousValue: T, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => T
A function that accepts up to four arguments. The reduce method calls the callback function one time for each element in the list.
Returns
reduceRight(callback, initialValue)
Calls the specified callback
function for all the nodes in the list, in reverse. The return value of the callback function is the accumulated result,
and is provided as an argument in the next call to the callback function.
Declaration
reduceRight(callback: (previousValue: T, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => T, initialValue: T): T;
Parameters
- callback
- (previousValue: T, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => T
A function that accepts up to four arguments. The reduce method calls the callback function one time for each element in the list.
- initialValue
- T
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callback
function provides this value as an argument instead of a list value.
Returns
reduceRight(callback, initialValue)
Calls the specified callback
function for all the nodes in the list, in reverse. The return value of the callback function is the accumulated result,
and is provided as an argument in the next call to the callback function.
Declaration
reduceRight<U>(callback: (previousValue: U, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => U, initialValue: U): U;
Type Parameters
- U
Parameters
- callback
- (previousValue: U, value: T, node: LinkedListNode<T>, list: LinkedList<T>) => U
A function that accepts up to four arguments. The reduce method calls the callback function one time for each element in the list.
- initialValue
- U
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callback
function provides this value as an argument instead of a list value.
Returns
shift()
Removes the first node from the list and returns its value. If the list is empty, undefined
is returned instead.
Declaration
shift(): T | undefined;
Returns
shiftNode()
Removes the first node from the list and returns it. If the list is empty, undefined
is returned instead.
Declaration
shiftNode(): LinkedListNode<T> | undefined;
Returns
some(callback, thisArg)
Declaration
some(callback?: (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean, thisArg?: any): boolean;
Parameters
- callback
- (value: T, node: LinkedListNode<T>, list: LinkedList<T>) => boolean
- thisArg
- any
Returns
unshift(value)
Inserts a new LinkedListNode containing value
at the beginning of the list.
Declaration
unshift(value: T): LinkedListNode<T>;
Parameters
- value
- T
The value to insert.
Returns
The new LinkedListNode for value
.
unshiftNode(newNode)
Inserts newNode
at the beginning of the list.
Declaration
unshiftNode(newNode: LinkedListNode<T>): void;
Parameters
Returns
values()
Declaration
values(): IterableIterator<T>;
Returns