Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/list/main/index.ts>List.Builder

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
interface List.Builder
import { type List } from "https://deno.land/x/rimbu@1.1.0/list/main/index.ts";
const { Builder } = List;

A mutable builder to create immutable List instances in a more efficient way. See the List documentation and the List.Builder API documentation

Examples

Example 1

const b = List.builder<T>();
b.append(1);
b.prepend(2);
b.insert(1, 3);
b.build().toArray();
// => [2, 3, 1]

Properties

readonly
length: number

Returns the amount of values in the builder.

readonly
isEmpty: boolean

Returns true if there are no values in the builder.

Methods

get(index: number): T | undefined

Returns the value in the List builder at the given index.

get<O>(index: number, otherwise: OptLazy<O>): T | O
updateAt(index: number, update: Update<T>): T | undefined

Updates the element at the given index with the given update value or function.

updateAt<O>(
index: number,
update: Update<T>,
otherwise: OptLazy<O>,
): T | O
set(index: number, value: T): T | undefined

Sets the element at the given index to the given value.

set<O>(
index: number,
value: T,
otherwise: OptLazy<O>,
): T | O
prepend(value: T): void

Adds the given value to the start of the builder values.

append(value: T): void

Adds the given value to the end of the builder values.

appendAll(values: StreamSource<T>): void

Adds all given values at the end of the builder values

insert(index: number, value: T): void

Inserts the given value at the given index in the builder.

remove(index: number): T | undefined

Removes the value at the given index in the builder.

remove<O>(index: number, otherwise: OptLazy<O>): T | O
forEach(f: (
value: T,
index: number,
halt: () => void,
) => void
, options?: { reversed?: boolean; state?: TraverseState; }
): void

Performs given function f for each value of the List builder.

build(): List<T>

Returns an immutable instance containing the values in this builder.

buildMap<T2 = T>(mapFun: (value: T) => T2): List<T2>

Returns an immutable instance containing the result of applying given mapFun to each value in the builder.