Create a SinglyLinkedList and optionally bulk-insert elements.
New SinglyLinkedList instance.
Protected Optional_toThe converter used to transform a raw element (R) into a public element (E).
Get the head node.
Head node or undefined.
Get the number of elements.
Current length.
Upper bound for length (if positive), or -1 when unbounded.
Maximum allowed length.
Get the tail node.
Tail node or undefined.
Protected_createProtected_create(Protected) Create a like-kind instance and seed it from an iterable.
A like-kind SinglyLinkedList instance.
Protected_create(Protected) Create a node from a value.
Value to wrap in a node.
A new SinglyLinkedListNode instance.
Protected_ensure(Protected) Normalize input into a node instance.
Element or node.
A SinglyLinkedListNode for the provided input.
Protected_ensure(Protected) Normalize input into a node predicate.
Element, node, or predicate.
A predicate taking a node and returning true/false.
Protected_getProtected_get(Protected) Iterate nodes from head to tail.
Iterator of nodes.
Protected_get(Protected) Get the previous node of a given node.
A node in the list.
Previous node or undefined.
Protected_getProtected_is(Protected) Check if input is a node predicate function.
Element, node, or node predicate.
True if input is a predicate function.
Protected_spawn(Protected) Spawn an empty like-kind list instance.
An empty like-kind SinglyLinkedList instance.
Returns an iterator over the structure's elements.
Rest...args: unknown[]Optional iterator arguments forwarded to the internal iterator.
An IterableIterator<E> that yields the elements in traversal order.
Insert a new element/node after an existing one.
Existing element or node.
Element or node to insert.
True if inserted.
Insert a new element/node at an index, shifting following nodes.
Zero-based index.
Element or node to insert.
True if inserted.
Insert a new element/node before an existing one.
Existing element or node.
Element or node to insert.
True if inserted.
Count how many nodes match a value/node/predicate.
Element, node, or node predicate to match.
Number of matches in the list.
Delete the first match by value/node.
OptionalelementOrNode: E | SinglyLinkedListNode<E>Element or node to remove; if omitted/undefined, nothing happens.
True if removed.
Fill a range with a value.
Value to set.
Inclusive start.
Exclusive end.
This list.
Finds the first element that satisfies the predicate and returns it.
Finds the first element of type S (a subtype of E) that satisfies the predicate and returns it.
The matched element typed as S, or undefined if not found.
Find a node by value, reference, or predicate.
OptionalelementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)Element, node, or node predicate to match.
Matching node or undefined.
Get the node reference at a given index.
Zero-based index.
Node or undefined.
Checks whether a strictly-equal element exists in the structure.
The element to test with === equality.
true if an equal element is found; otherwise false.
Linked-list optimized indexOf (forwards scan).
Value to match.
Start position.
Index or -1.
Type guard: check whether the input is a SinglyLinkedListNode.
Element, node, or predicate.
True if the value is a SinglyLinkedListNode.
Linked-list optimized lastIndexOf (reverse scan).
Value to match.
Start position.
Index or -1.
Map values into a new list (possibly different element type).
A new SinglyLinkedList with mapped values.
Append an element/node to the tail.
Element or node to append.
True when appended.
Append a sequence of elements/nodes.
Iterable of elements or nodes (or raw records if toElementFn is provided).
Array of per-element success flags.
Find the first value matching a predicate (by node).
Element, node, or node predicate to match.
Matched value or undefined.
Set the element value at an index.
Zero-based index.
New value.
True if updated.
Remove and/or insert elements at a position (array-like behavior).
Start index (clamped to [0, length]).
OptionaldeleteCount: number = 0Number of elements to remove (default 0).
Optional Rest...items: E[]Elements to insert after start.
A new list containing the removed elements (typed as this).
Prepend an element/node to the head.
Element or node to prepend.
True when prepended.
Prepend a sequence of elements/nodes.
Iterable of elements or nodes (or raw records if toElementFn is provided).
Array of per-element success flags.
Staticfrom
Singly linked list with O(1) push/pop-like ends operations and linear scans.
Remarks
Time O(1), Space O(1)
Example