# rope-sequence

> Rope-based persistent sequence type

Latest version **1.3.4** (published 2023-05-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install rope-sequence
pnpm add rope-sequence
yarn add rope-sequence
bun add rope-sequence
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.3.4 |
| Published | 2023-05-17 |
| First published | 2016-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 46 |
| Author | Marijn Haverbeke |
| Maintainers | marijn |
| Keywords | persistent, data, structure, rope, sequence |

## Links

- npm: https://www.npmjs.com/package/rope-sequence
- Repository: https://github.com/marijnh/rope-sequence
- Homepage: https://github.com/marijnh/rope-sequence#readme
- Issues: https://github.com/marijnh/rope-sequence/issues
- npm.io page: https://npm.io/package/rope-sequence

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 1.3.4 (latest) — 2023-05-17
- 1.3.3 — 2022-05-13
- 1.3.2 — 2019-11-20
- 1.3.1 — 2019-11-20
- 1.3.0 — 2019-11-08
- 1.2.2 — 2016-12-01
- 1.2.1 — 2016-09-21
- 1.2.0 — 2016-07-15
- 1.1.0 — 2016-07-14
- 1.0.0 — 2016-07-13

## README

# rope-sequence

This module implements a single data type, `RopeSequence`, which is a
persistent sequence type implemented as a loosely-balanced
[rope](https://www.cs.rit.edu/usr/local/pub/jeh/courses/QUARTERS/FP/Labs/CedarRope/rope-paper.pdf).
It supports appending, prepending, and slicing without doing a full
copy. Random access is somewhat more expensive than in an array
(logarithmic, with some overhead), but should still be relatively
fast.

Licensed under the MIT license.

## class `RopeSequence<T>`

`static `**`from`**`(?union<[T], RopeSequence<T>>) → RopeSequence<T>`

Create a rope representing the given array, or return the rope itself
if a rope was given.

`static `**`empty`**`: RopeSequence<T>`

The empty rope.

**`length`**`: number`

The length of the rope.

**`append`**`(union<[T], RopeSequence<T>>) → RopeSequence<T>`

Append an array or other rope to this one, returning a new rope.

**`prepend`**`(union<[T], RopeSequence<T>>) → RopeSequence<T>`

Prepend an array or other rope to this one, returning a new rope.

**`slice`**`(from: ?number = 0, to: ?number = this.length) → RopeSequence<T>`

Create a rope repesenting a sub-sequence of this rope.

**`get`**`(index: number) → T`

Retrieve the element at the given position from this rope.

**`forEach`**`(f: fn(element: T, index: number) → ?bool, from: ?number, to: ?number)`

Call the given function for each element between the given indices.
This tends to be more efficient than looping over the indices and
calling `get`, because it doesn't have to descend the tree for every
element.

`to` may be less then `from`, in which case the iteration will happen
in reverse (starting at index `from - 1`, down to index `to`.

The iteration function may return `false` to abort iteration early.

**`map`**`(f: fn(element: T, index: number) → U, from: ?number, to: ?number) → [U]`

Map the given functions over the elements of the rope, producing a
flat array.

**`flatten`**`() → [T]`

Return the content of this rope as an array.

---
_Source: https://npm.io/package/rope-sequence · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
