Skip to main content

interface RSetBase.Builder<T,Tp>

undocumented

Implemented by: RSet.Builder<T>, OrderedSetBase.Builder<T,Tp>, HashSet.Builder<T>, SortedSet.Builder<T>

Type parameters

NameConstraintsDefaultDescription
Tundocumented
TpRSetBase.Types RSetBase.Typesundocumented

Properties

isEmpty

Returns true if there are no values in the builder.

Definition

readonly isEmpty: boolean;

example
HashSet.of(1, 2, 3).toBuilder().isEmpty
// => false

size

Returns the amount of values in the builder.

Definition

readonly size: number;

example
HashSet.of(1, 2, 3).toBuilder().size
// => 3

Methods

add

Adds given value to the builder.

Definition

add(value: T): boolean;

Parameters

NameTypeDescription
valueT
example
const s = HashSet.of(1, 2, 3).toBuilder()
s.add(2) // => false
s.add(10) // => true

addAll

Adds the values in given values StreamSource to the builder.

Definition

addAll(values: StreamSource<T>): boolean;

Parameters

NameTypeDescription
valuesStreamSource<T>
example
const s = HashSet.of(1, 2, 3).toBuilder()
s.addAll([1, 3]) // => false
s.addAll([2, 10]) // => true

build

Returns an immutable instance containing the values in this builder.

Definition

build(): WithElem<Tp, T>['normal'];

example
const s = HashSet.of(1, 2, 3).toBuilder()
const s2: HashSet<number> = m.build()

forEach

Performs given function f for each value of the builder.

Definition

forEach(f: (value: T, index: number, halt: () => void) => void, state?: TraverseState): void;

Parameters

NameTypeDescription
f(value: T, index: number, halt: () => void) => voidthe function to perform for each element, receiving:
- value: the next element
- index: the index of the element
- halt: a function that, if called, ensures that no new elements are passed
stateTraverseState
throws

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

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

O(N)

has

Returns true if the given value is present in the builder.

Definition

has<U = T>(value: RelatedTo<T, U>): boolean;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valueRelatedTo<T, U>the value to look for
example
const s = HashSet.of(1, 2, 3).toBuilder()
s.has(2) // => true
s.has(10) // => false

remove

Remove the given value from the builder.

Definition

remove<U = T>(value: RelatedTo<T, U>): boolean;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valueRelatedTo<T, U>
example
const s = HashSet.of(1, 2, 3).toBuilder()
s.remove(10) // => false
s.remove(2) // => true

removeAll

Removes the values in given values StreamSource from this builder.

Definition

removeAll<U = T>(values: StreamSource<RelatedTo<T, U>>): boolean;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valuesStreamSource<RelatedTo<T, U>>a StreamSource of values
example
const s = HashSet.of(1, 2, 3).toBuilder()
s.removeAll([1, 3]) // => false
s.removeAll([2, 10]) // => true