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.

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

import { Stacks } from "https://unpkg.com/@ixfx/collections/bundle"
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`

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

import { Stacks } from "https://unpkg.com/@ixfx/collections/bundle"
const s = Stacks.mutable();
s.push(`a`, `b`);
s.peek; // `b`
s.pop(); // `b`
s.peek; // `a`
// Sub module
import { Stacks } from "@ixfx/collections.js"
// Eg: Stacks.immutable();
// Whole module
import * as Collections from "@ixfx/collections.js"
// Eg: Collections.Stacks.immutable();
// From bundle
import { Collections } from "@ixfx"
// Eg: Collections.Stacks.immutable();
// And within your HTML's <HEAD> </HEAD> block:
<script type="importmap">{ "imports": { "@ixfx":"/ixfx/index.js", "@ixfx/": "/ixfx/" } }</script>