The type of elements stored in the stack.
Optional
initialValues: readonly T[]Optional array of initial elements to populate the stack. Elements will be popped in reverse order of how they appear in the array (last array element will be popped first). If provided, the initial buffer capacity will be at least twice the array length.
A new Stack instance optimized for high-performance LIFO operations.
const stack = createStack<string>();
assert.ok(stack.isEmpty);
assert(stack.size === 0);
stack.push('first');
// eslint-disable-next-line unicorn/prefer-single-call
stack.push('second');
assert.notOk(stack.isEmpty);
assert(stack.size === 2);
assert.deepStrictEqual(stack.pop(), Optional.some('second'));
assert.deepStrictEqual(stack.pop(), Optional.some('first'));
assert.deepStrictEqual(stack.pop(), Optional.none);
const seededStack = createStack([10, 20, 30]);
assert(seededStack.size === 3);
assert.deepStrictEqual(seededStack.pop(), Optional.some(30));
Creates a new Stack instance with LIFO (Last-In, First-Out) behavior using a high-performance dynamic array.
This factory function creates an optimized stack implementation that maintains excellent performance characteristics for both push and pop operations. The underlying dynamic array automatically resizes to accommodate growing workloads while providing predictable O(1) operations.
Implementation Features:
Performance Benefits: