Skip to content

Stack

Module Collections.Stacks

A stack has the logic of a pile of plates. First in, last out. With a stack, you’re only able to work on the top-most, most recently added item.

Immutable

Stacks.immutable creates an immutable stack of Interface Stacks.IStackImmutable

import { Stacks } from "https://unpkg.com/ixfx/dist/collections.js"
let s = Stacks.immutable();
s = s.push(`a`, `b`); // Add two strings
// Peek looks at the top of the stack
// (ie most recently added)
s.peek; // `b`
// Remove item from top of stack
s = s.pop();
s.peek // `a`

Mutable

Stacks.mutable creates a mutable stack of Interface Stacks.IStackMutable

import { Stacks } from "https://unpkg.com/ixfx/dist/collections.js"
const s = new Stacks.mutable();
s.push(`a`, `b`);
s.peek; // `b`
s.pop(); // `b`
s.peek; // `a`