import { type List } from "https://deno.land/x/rimbu@1.0.3/list/mod.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
Example 1
const b = List.builder<T>();
b.append(1);
b.prepend(2);
b.insert(1, 3);
b.build().toArray();
// => [2, 3, 1]
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
Updates the element at the given index
with the given update
value or function.
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
Performs given function f
for each value of the List builder.
build(): List<T>
Returns an immutable instance containing the values in this builder.