包详细信息

@rimbu/core

rimbu-org13.7kMIT2.0.7

Immutable collections and tools for TypeScript

collection, immutable, list, map

自述文件

Rimbu Logo

npm version License Types Included Node Bun ESM + CJS

@rimbu/core

All core Rimbu collections and utilities from a single import.

@rimbu/core is the convenience entry point to the Rimbu ecosystem. It re‑exports the public APIs of the main collection packages (lists, maps, sets, graphs, tables, streams, and more) together with the shared utilities from @rimbu/common, so you can build rich immutable data models without juggling many imports.

Use it when you want:

  • a single dependency that gives you the full set of Rimbu core collections
  • a consistent, fully typed API for immutable data structures
  • both direct imports and a creation “menu” (@rimbu/core/menu) for concise, expressive code

Table of Contents

  1. Why @rimbu/core?
  2. Feature Highlights
  3. Quick Start
  4. Import Styles
  5. What’s Included
  6. Installation
  7. Ecosystem & Integration
  8. Contributing
  9. License
  10. Attributions

Why @rimbu/core?

Rimbu is a collection library focused on immutable, persistent data structures with a strong TypeScript story. Each collection type lives in its own package (e.g. @rimbu/list, @rimbu/hashed, @rimbu/sorted, …), and @rimbu/common provides shared types and utilities used across the ecosystem.

@rimbu/core brings these together:

  • Single import – access all main collections through @rimbu/core.
  • Shared utilities included – get everything from @rimbu/common as part of the same dependency.
  • Consistent experience – unified API surface, aligned docs, and the same immutable semantics throughout.

If you just want to “use Rimbu” without thinking about which sub‑package exports which type, @rimbu/core is what you install.

For full documentation, see the Rimbu Docs and the @rimbu/core API reference.


Feature Highlights

  • All main collections in one placeList, Stream / AsyncStream, HashMap, SortedMap, HashSet, SortedSet, BiMap, BiMultiMap, Table, graphs, multimaps, multisets, and more.
  • Immutable & persistent semantics – structural sharing for efficient copies and diffs.
  • Typed end‑to‑end – works great in TypeScript, with rich generics and non‑empty refinements.
  • Creation “menu” – optional namespace‑style API via @rimbu/core/menu for expressive code like Rimbu.Map.Sorted.of(...).
  • Cross‑runtime support – Node ≥ 18, Deno, Bun, and modern browsers (ESM + CJS builds included).

Each individual collection has its own dedicated documentation and examples, but @rimbu/core lets you reach them all from a single dependency.


Quick Start

Direct imports

import { List, Stream, SortedMap } from '@rimbu/core';

// Build an immutable list
const list = List.of(1, 3, 2, 4, 2);

// Transform it into a stream of entry tuples
const stream = Stream.from(list).map((v) => [v, String(v * 2)] as const);

// Materialize into a sorted map
const map = SortedMap.from(stream);

console.log(map.toArray());
// => [[1, '2'], [2, '4'], [3, '6'], [4, '8']]

Try it online

Experiment with Rimbu (including @rimbu/core) in the browser using the Rimbu Sandbox on CodeSandbox.


Import Styles

1. Direct imports from @rimbu/core

Recommended when you only need a few specific types:

import { List, HashMap, Stream } from '@rimbu/core';

const list = List.of(1, 2, 3);
const map = HashMap.of(['a', 1], ['b', 2]);

const result = Stream.from(map.entries()).toArray();

All public types from the core collection packages are re‑exported here, so you rarely need to import the sub‑packages directly.

2. Using the creation “menu” from @rimbu/core/menu

The “menu” groups key Rimbu types into a single namespace, which is convenient for quick prototyping or REPL usage:

import Rimbu from '@rimbu/core/menu';

const list = Rimbu.List.of(1, 3, 2, 4, 2);

const stream = Rimbu.Stream.from(list).map((v) => [v, String(v * 2)] as const);

const map = Rimbu.Map.Sorted.from(stream);

console.log(map.toArray());
// => [[1, '2'], [2, '4'], [3, '6'], [4, '8']]

Under the hood, this uses the same types that are exported from @rimbu/core, organized into namespaces like Rimbu.Map, Rimbu.Set, Rimbu.Table, and Rimbu.Graph.


What’s Included

@rimbu/core re‑exports the public APIs of the following sub‑packages. Use these packages directly when you need package‑specific documentation, but feel free to import their types through @rimbu/core:

Package Description
@rimbu/bimap Bidirectional map where each key maps to a unique value and vice versa.
@rimbu/bimultimap Bidirectional multimap allowing many‑to‑many mappings between keys and values.
@rimbu/collection-types Shared collection type definitions used by all Rimbu collections.
@rimbu/common Public types and utility functions used throughout the library.
@rimbu/deep Tools (such as Deep and Tuple) for treating plain JS objects as immutable structures.
@rimbu/graph Graph implementations for modelling data as nodes and edges.
@rimbu/hashed HashMap / HashSet implementations using hash functions for fast key retrieval.
@rimbu/list Immutable List for ordered sequences with efficient random access and updates.
@rimbu/multimap Map where each key can be associated with multiple values.
@rimbu/multiset Set where elements can occur multiple times.
@rimbu/ordered OrderedMap / OrderedSet that retain insertion order.
@rimbu/proximity ProximityMap for retrieving values based on key proximity.
@rimbu/sorted SortedMap / SortedSet implementations that keep elements sorted via compare functions.
@rimbu/stream Lazy, composable Stream / AsyncStream types for processing sequences of data.
@rimbu/table Table data structures where row/column key pairs map to a single value.

For a complete overview, start from the Rimbu documentation or jump directly to the @rimbu/core API docs.


Installation

Node / Bun / npm / Yarn / Deno

npm install @rimbu/core
# or
yarn add @rimbu/core
# or
bun add @rimbu/core
# or
deno add npm:@rimbu/core

Browser / ESM

@rimbu/core ships both ESM and CJS builds. Use it with any modern bundler (Vite, Webpack, esbuild, Bun, etc.) or directly in Node ESM projects.


Ecosystem & Integration

  • Part of the broader Rimbu collection ecosystem – interoperates with packages like @rimbu/hashed, @rimbu/ordered, @rimbu/collection-types, and @rimbu/stream.
  • Designed for immutable, persistent data models in TypeScript and JavaScript applications.
  • Works well in Node services, browser apps, and Deno/Bun runtimes.

Explore more at the Rimbu documentation and the @rimbu/core API docs.


Contributing

We welcome contributions! See the Contributing guide for details.

Contributors

Made with contributors-img.


License

MIT © Rimbu contributors. See LICENSE for details.


Attributions

Created and maintained by Arvid Nicolaas. Logo © Rimbu.