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
Name | Description |
---|---|
T | the value type |
Properties
isEmpty
Returns true if there are no values in the builder.
isEmpty
size
Returns the amount of values in the builder.
size
Methods
add
Adds given value
to the builder.
add
value
to the builder.addAll
Adds the values in given values
StreamSource
to the builder.
addAll
values
StreamSource
to the builder.Definition
addAll(values:
StreamSource
<T>): boolean;
Parameters
Name | Type | Description |
---|---|---|
values | StreamSource <T> |
const s = HashSet.of(1, 2, 3).toBuilder()
s.addAll([1, 3]) // => false
s.addAll([2, 10]) // => true
Overrides
build
Returns an immutable instance containing the values in this builder.
build
forEach
Performs given function f
for each value of the builder.
forEach
f
for each value of the builder.Definition
forEach(f: (value: T, index: number, halt: () => void) => void, options?: {
state?:
TraverseState
;
}): void;
Parameters
Name | Type | Description |
---|---|---|
f | (value: T, index: number, halt: () => void) => void | the 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 |
RibuError.ModifiedBuilderWhileLoopingOverItError if the builder is modified while looping over it
HashSet.of(1, 2, 3).toBuilder.forEach((value, i, halt) => {
console.log([value, i]);
if (i >= 1) halt();
})
// => logs [1, 0] [2, 1]
O(N)
Overrides
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.
getAtIndex
Definitions
getAtIndex(index: number): T
|
undefined;
getAtIndex<O>(index: number, otherwise:
OptLazy
<O>): T
|
O;
Parameters
Name | Type | Description |
---|---|---|
index | number | the index in the key sort order |
negative index values will retrieve the values from the end of the sort order, e.g. -1 is the last value
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.
has
value
is present in the builder.max
Returns the maximum value of the SortedSet builder, or a fallback value (default: undefined) if the builder is empty.
max
min
Returns the minimum value of the SortedSet builder, or a fallback value (default: undefined) if the builder is empty.
min
remove
Remove the given value
from the builder.
remove
value
from the builder.removeAll
Removes the values in given values
StreamSource
from this builder.
removeAll
values
StreamSource
from this builder.Definition
removeAll<U = T>(values:
StreamSource
<
RelatedTo
<T, U>>): boolean;
Type parameters
Name | Default | Description |
---|---|---|
U | T |
Parameters
Name | Type | Description |
---|---|---|
values | StreamSource < RelatedTo <T, U>> | a StreamSource of values |
const s = HashSet.of(1, 2, 3).toBuilder()
s.removeAll([1, 3]) // => false
s.removeAll([2, 10]) // => true