interface SortedMap.Builder<K,V>
A mutable SortedMap
builder used to efficiently create new immutable instances. See the Map documentation and the SortedMap.Builder API documentation
Type parameters
Name | Description |
---|---|
K | the key type |
V | the value type |
Methods
getAtIndex
Returns the entry with its key at the given index of the key sort order of the SortedMap builder, or a fallback value (default: undefined) if the index is out of bounds.
getAtIndex
Definitions
getAtIndex(index: number): readonly [K, V]
|
undefined;
getAtIndex<O>(index: number, otherwise:
OptLazy
<O>): readonly [K, V]
|
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 = SortedMap.of(['b', 2], ['d', 4], ['a', 1], ['c', 3]).toBuilder();
console.log(b.getAtIndex(1))
// => ['b', 2]
console.log(b.getAtIndex(-1))
// => ['d', 4]
console.log(b.getAtIndex(10))
// => undefined
console.log(b.getAtIndex(10, 'q'))
// => 'q'
max
Returns the entry with the maximum key of the SortedMap Builder, or a fallback value (default: undefined) if the builder is empty.
max
Definitions
max(): readonly [K, V]
|
undefined;
max<O>(otherwise:
OptLazy
<O>): readonly [K, V]
|
O;
const b = SortedMap.of(['b', 2], ['d', 4], ['a', 1], ['c', 3]).toBuilder();
console.log(b.max())
// => ['a', 1]
console.log(b.max('q'))
// => ['a', 1]
console.log(SortedMap.builder().max())
// => undefined
console.log(SortedMap.builder().max('q'))
// => 'q'
min
Returns the entry with the minimum key of the SortedMap Builder, or a fallback value (default: undefined) if the builder is empty.
min
Definitions
min(): readonly [K, V]
|
undefined;
min<O>(otherwise:
OptLazy
<O>): readonly [K, V]
|
O;
const b = SortedMap.of(['b', 2], ['d', 4], ['a', 1], ['c', 3]).toBuilder();
console.log(b.min())
// => ['a', 1]
console.log(b.min('q'))
// => ['a', 1]
console.log(SortedMap.builder().min())
// => undefined
console.log(SortedMap.builder().min('q'))
// => 'q'