Skip to main content

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

NameDescription
Kthe key type
Vthe 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.

Definitions

getAtIndex(index: number): readonly [K, V] | undefined;

getAtIndex<O>(index: number, otherwise: OptLazy<O>): readonly [K, V] | 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 = 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.

Definitions

max(): readonly [K, V] | undefined;

max<O>(otherwise: OptLazy<O>): readonly [K, V] | O;

example
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.

Definitions

min(): readonly [K, V] | undefined;

min<O>(otherwise: OptLazy<O>): readonly [K, V] | O;

example
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'