Skip to main content

interface SortedSet.Builder<T>

A mutable SortedSet builder used to efficiently create new immutable instances. See the Set documentation and the SortedSet.Builder API documentation

Extends: RSetBase.Builder<T,Tp>

Type parameters

NameDescription
Tthe value type

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

Overrides

Builder.isEmpty

size

Returns the amount of values in the builder.

Definition

readonly size: number;

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

Overrides

Builder.size

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

Overrides

Builder.add

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

Overrides

Builder.addAll

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()

Overrides

Builder.build

forEach

Performs given function f for each value of the builder.

Definition

forEach(f: (value: T, index: number, halt: () => void) => void, options?: {
      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
options{
      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
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)

Overrides

Builder.forEach

getAtIndex

Returns the value at the given index of the value sort order of the SortedSet builder, or a fallback value (default: undefined) if the index is out of bounds.

Definitions

getAtIndex(index: number): T | undefined;

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

Parameters

NameTypeDescription
indexnumberthe index in the key sort order
note

negative index values will retrieve the values from the end of the sort order, e.g. -1 is the last value

example
const b = SortedSet.of('b', 'd', 'a', 'c').toBuilder();
console.log(b.getAtIndex(1))
// => 'b'
console.log(b.getAtIndex(-1))
// => 'd'
console.log(b.getAtIndex(10))
// => undefined
console.log(b.getAtIndex(10, 'q'))
// => 'q'

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

Overrides

Builder.has

max

Returns the maximum value of the SortedSet builder, or a fallback value (default: undefined) if the builder is empty.

Definitions

max(): T | undefined;

max<O>(otherwise: OptLazy<O>): T | O;

example
const b = SortedSet.of('b', 'd', 'a', 'c').toBuilder();
console.log(b.max())
// => 'd'
console.log(b.max('q'))
// => 'd'
console.log(SortedSet.empty().max())
// => undefined
console.log(SortedSet.empty().max('q'))
// => 'q'

min

Returns the minimum value of the SortedSet builder, or a fallback value (default: undefined) if the builder is empty.

Definitions

min(): T | undefined;

min<O>(otherwise: OptLazy<O>): T | O;

example
const b = SortedSet.of('b', 'd', 'a', 'c').toBuilder();
console.log(b.min())
// => 'a'
console.log(b.min('q'))
// => 'a'
console.log(SortedSet.empty().min())
// => undefined
console.log(SortedSet.empty().min('q'))
// => 'q'

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

Overrides

Builder.remove

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

Overrides

Builder.removeAll