Skip to main content

Immutable Collections for Typescript

Efficient immutable balanced tree and hash array mapped tree

Balanced Binary Tree

This library contains an implementation of an efficient immutable balanced binary tree. It supports O(log n) insert and delete, along with many more bulk modification operations. Keys are kept in sorted order, allowing iteration in ascending and descending order of keys.

Hash Array Mapped Trie

This library contains an implementation of an efficient immutable hash array mapped trie for O(1) operations, along with efficient bulk modification operations.

Zero Dependencies

This library has no dependencies and is written in pure Typescript. It supports tree-shaking to produce small bundles.

Extensivly Tested

This library contains a large test suite with full code coverage of all operations and all edge cases.

Lazy Sequence Operations

This library contains a data pipeline API for lazy sequence operations, similar to LINQ in C# or lodash/ramda. It wraps Javascript Iterables and provides a rich set of operations for mapping and transforming data, including terminating the pipeline with an immutable tree or hashmap.

Shallow Comparison

This library guarantees that if a modification operation such as delete does not actually change the tree, the javascript object representing the data is returned unchanged. This allows React.memo or other memoization techniques to easily be used.

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

const m = OrderedMap.from([ [1, "Hello"], [2, "World"]]);
console.log(m.get(1)); // prints Hello
console.log(m.get(2)); // prints World

const m2 = m.set(1, "Goodbye");
console.log(m2.get(1)); // prints Goodbye
console.log(m.get(1)); // prints Hello

const union = m.union(m2, (a, b) => a + b);
console.log(union.get(1)); // prints HelloGoodbye
console.log(union.get(2)); // prints World