Skip to main content

class GenBuilder<T>

undocumented

Implements: List.Builder<T>

Type parameters

NameDescription
Tundocumented

Properties

_lock

undocumented

Definition

_lock: number;

append

undocumented

Definition

append: (value: T) => void;

appendAll

undocumented

Definition

appendAll: (values: StreamSource<T>) => void;

build

undocumented

Definition

build: () => List<T>;

builder

undocumented

Definition

builder?: LeafBuilder<T> | undefined;

buildMap

undocumented

Definition

buildMap: <T2>(f: (value: T) => T2) => List<T2>;

context

undocumented

Definition

readonly context: ListContext;

forEach

undocumented

Definition

forEach: (f: (value: T, index: number, halt: () => void) => void, options?: {
    reversed?: boolean;
    state?: TraverseState;
  }) => void;

get

undocumented

Definition

get: <O>(index: number, otherwise?: OptLazy<O>) => T | O;

insert

undocumented

Definition

insert: (index: number, value: T) => void;

isEmpty

undocumented

Definition

get isEmpty(): boolean;

Overrides

Builder.isEmpty

length

undocumented

Definition

get length(): number;

Overrides

Builder.length

prepend

undocumented

Definition

prepend: (value: T) => void;

remove

undocumented

Definition

remove: <O>(index: number, otherwise?: OptLazy<O>) => T | O;

set

undocumented

Definition

set: <O>(index: number, value: T, otherwise?: OptLazy<O>) => T | O;

updateAt

undocumented

Definition

updateAt: <O>(index: number, update: Update<T>, otherwise?: OptLazy<O>) => T | O;

Methods

append

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

Definition

append(value: T): void;

Parameters

NameTypeDescription
valueTthe value to append
example
const m = List.of(1, 2, 3).toBuilder()
m.append(10)
m.build().toArray()
// => [1, 2, 3, 10]
note

O(logB(N)) for block size B - mosly o(1)

Overrides

Builder.append

appendAll

Adds all given values at the end of the builder values

Definition

appendAll(values: StreamSource<T>): void;

Parameters

NameTypeDescription
valuesStreamSource<T>a StreamSource containing values to add
example
const m = List.of(1, 2, 3).toBuilder()
m.appendAll([10, 11])
m.build().toArray()
// => [1, 2, 3, 10, 11]

Overrides

Builder.appendAll

appendArray

undocumented

Definition

appendArray(array: T[]): void;

Parameters

NameTypeDescription
arrayT[]

appendFullOrLastWindow

undocumented

Definition

appendFullOrLastWindow(window: T[]): void;

Parameters

NameTypeDescription
windowT[]

build

Returns an immutable instance containing the values in this builder.

Definition

build(): List<T>;

example
const m = List.of(1, 2, 3).toBuilder()
const m2: List<number> = m.build()
m.toArray()
// => [1, 2, 3]

Overrides

Builder.build

buildMap

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

Definition

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

Type parameters

NameDefaultDescription
T2T

Parameters

NameTypeDescription
mapFun(value: T) => T2
example
const m = List.of(1, 2, 3).toBuilder()
const m2: List<number> = m.buildMap(v => String(v))
m.toArray()
// => ['1', '2', '3']

Overrides

Builder.buildMap

checkLock

undocumented

Definition

checkLock(): void;

forEach

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

Definition

forEach(f: (value: T, index: number, halt: () => void) => void, options?: {
      reversed?: boolean;
      state?: TraverseState;
    }): void;

Parameters

NameTypeDescription
f(value: T, index: number, halt: () => void) => voidthe function to perform for each element, receiving
- value: the next value
- index: the index of the value
- halt: a function that, if called, ensures that no new elements are passed
options{
      reversed?: boolean;
      state?: TraverseState;
    }
(optional) an object containing the following properties:
- state: (optional) the traversal state
throws

RibuError.ModifiedBuilderWhileLoopingOverItError if the builder is modified while looping over it

example
List.of(0, 1, 2, 3).toBuilder().forEach((value, i, halt) => {
console.log(value * 2);
if (i >= 1) halt();
})
// => logs 0 2
note

O(N)

Overrides

Builder.forEach

get

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

Definitions

get(index: number): T | undefined;

get<O>(index: number, otherwise: OptLazy<O>): T | O;

Parameters

NameTypeDescription
indexnumberthe element index
note

a negative index will be treated as follows:
- -1: the last value in the list
- -2: the second-last value in the list
- ...etc

example
const m = List.of(0, 1, 2).toBuilder()
m.get(5) // => undefined
m.get(5, 'other') // => 'other'
m.get(1, 'other') // => 1
m.get(-1) // => 2
note

O(logB(N)) for block size B

Overrides

Builder.get

insert

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

Definition

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

Parameters

NameTypeDescription
indexnumberthe index at which to insert the value
valueTthe value to insert
note

a negative index will be treated as follows:
- -1: the last value in the list
- -2: the second-last value in the list
- ...etc

example
const m = List.of(1, 2, 3).toBuilder()
m.insert(1, 10)
m.build().toArray()
// => [1, 10, 2, 3]

Overrides

Builder.insert

prepend

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

Definition

prepend(value: T): void;

Parameters

NameTypeDescription
valueTthe value to prepend
example
const m = List.of(1, 2, 3).toBuilder()
m.prepend(10)
m.build().toArray()
// => [10, 1, 2, 3]
note

O(logB(N)) for block size B - mosly o(1)

Overrides

Builder.prepend

remove

Removes the value at the given index in the builder.

Definitions

remove(index: number): T | undefined;

remove<O>(index: number, otherwise: OptLazy<O>): T | O;

Parameters

NameTypeDescription
indexnumberthe index at which to remove a value
example
const m = List.of(1, 2, 3).toBuilder()
m.remove(10) // => undefined
m.remove(10, 'a') // => 'a'
m.remove(1) // => 2
m.remove(0, 'a') // => 1

Overrides

Builder.remove

set

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

Definitions

set(index: number, value: T): T | undefined;

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

Parameters

NameTypeDescription
indexnumberthe index of the element to set.
valueTthe new value to set.
note

a negative index will be treated as follows:
- -1: the last element in the list
- -2: the second-last element in the list
- ...etc

example
const m = List.of(1, 2, 3).toBuilder()
m.set(0, 10) // => 1
m.set(1, 10, 'a') // => 2
m.set(10, 0) // => undefined
m.set(10, 0, 'a') // => 'a'
note

O(logB(N)) for block size B

Overrides

Builder.set

updateAt

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

Definitions

updateAt(index: number, update: Update<T>): T | undefined;

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

Parameters

NameTypeDescription
indexnumberthe index of the element to update
updateUpdate<T>the new value or function taking the current value and returning a new value
note

a negative index will be treated as follows:
- -1: the last element in the list
- -2: the second-last element in the list
- ...etc

example
const m = List.of(1, 2, 3).toBuilder()
m.updateAt(0, 10) // => 1
m.updateAt(1, 10, 'a') // => 2
m.updateAt(10, 0) // => undefined
m.updateAt(10, 0, 'a') // => 'a'
note

O(logB(N)) for block size B

Overrides

Builder.updateAt