
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@chainsafe/persistent-ts
Advanced tools
Persistent data structures for TypeScript.
Persistent data structures are entirely immutable, but efficiently share elements between each other. For example, prepending to a persisistent list only creates a new node that references the old list. Prepending to an array, however, requires copying an entire array. Persistent data structures are thus better suited for use in immutable environments.
This library isn't as developed as others, such as immutable js. However, it can provide alternative data structures, and hopefully more readable implementations. Unlike immutable js specifically, this implementation is also Typescript first, whereas that library adds type annotations after the fact. This makes for an api centered around generics, and not necessarily acccomadating JS' indiosyncracies.
This library only implements a handful of data structures at the moment.
List
is a singly linked list. Here's a sample of its operations:
// ()
List.empty<number>();
// (1, 2, 3, 4)
List.of(1, 2, 3, 4);
// (1, 2)
List.of(1).prepend(2);
// 1
List.of(1, 2, 3).head();
// (2, 3)
List.of(1, 2, 3).tail();
// (1, 2, 3)
List.of(1, 2, 3, 4).take(3);
// (4)
List.of(1, 2, 3, 4).drop(3);
//[1, 2, 3, 4]
[...List.of(1, 2, 3, 4)];
Vector
is a Radix Tree in the vein of clojure's data structure.
This can be used as an immutable sequence with efficient random access and
appending. Here's a sample of its operations:
// []
Vector.empty<number>();
// [1]
Vector.empty().append(1);
// []
Vector.from([1]).pop();
// 3
Vector.from([1, 2, 3]).get(2);
// [1, 2, 100]
Vector.from([1, 2, 3]).set(2, 100);
FAQs
Persistent data structures for TypeScript.
The npm package @chainsafe/persistent-ts receives a total of 1,344 weekly downloads. As such, @chainsafe/persistent-ts popularity was classified as popular.
We found that @chainsafe/persistent-ts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.