Skip to main content

Immutable Collections

Zero dependency library for immutable collections in typescript.

Features

Install

Install with npm/yarn/pnpm from the npm registry.

Use

To use the class-based API, import from the @seedtactics/immutable-collections module directly. See the comparison docs to decide between a HashMap or an OrderedMap.

import { HashMap, OrderedMap } from "@seedtactics/immutable-collections";

For smaller bundler size but slightly less ergonomic to use, import the hamt or tree submodules. See the bundle size docs for full details comparing the two APIs. You should only use either the class based API or the function API; they export equivalent functionality.

import * as HAMT from "@seedtactics/immutable-collections/hamt";
import * as tree from "@seedtactics/immutable-collections/tree";

Lists

This library does not implement an immutable list. The funkia/list library already contains a high-quality immutable list which can be used in conjunction with the immutable maps in this library. An alternative is to use an OrderedMap as a kind of sequence by using a number key. This works well for sorted lists by using the sort as the key. Then, whenever you iterate the values in the OrderedMap, the values will be in ascending order of keys. The OrderedMap also has functions to view, modify, or pop the entry with the largest or smallest key, allowing list operations at the ends of the list.