interface SortedSet<T>
A type-invariant immutable Set of value type T. In the Set, there are no duplicate values. See the Set documentation and the SortedSet API documentation
Companion namespace: SortedSet
Implemented by: SortedSetEmpty<T>
, SortedSet.NonEmpty<T>
Type parameters
Name | Description |
---|---|
T | the value type |
- The
SortedSet
keeps the inserted values in sorted order according to the context'scomp
Comp
instance.
const s1 = SortedSet.empty<string>()
const s2 = SortedSet.of('a', 'b', 'c')
Methods
drop
Returns a SortedSet containing all but the the first amount
of value of this SortedSet.
drop
amount
of value of this SortedSet.Definition
drop(amount: number):
SortedSet
<T>;
Parameters
Name | Type | Description |
---|---|---|
amount | number | the amount of elements to keep |
a negative amount
drops the last values instead of the first, e.g. -2 is the last 2 elements
const m = SortedSet.of('b', 'd', 'a', 'c').asNormal();
console.log(m.drop(2).toArray())
// => ['c', 'd']
console.log(m.drop(-2).toArray())
// => ['a', 'b']
getAtIndex
Returns the value at the given index of the value sort order of the SortedSet, 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 m = SortedSet.of('b', 'd', 'a', 'c').asNormal();
console.log(m.getAtIndex(1))
// => 'b'
console.log(m.getAtIndex(-1))
// => 'd'
console.log(m.getAtIndex(10))
// => undefined
console.log(m.getAtIndex(10, 'q'))
// => 'q'
max
Returns the maximum value of the SortedSet, or a fallback value (default: undefined) if the SortedSet is empty.
max
min
Returns the minimum value of the SortedSet, or a fallback value (default: undefined) if the SortedSet is empty.
min
slice
Returns a SortedSet containing only those values that are within the given keyRange
.
slice
keyRange
.sliceIndex
Returns a SortedSet containing only those values that are within the given range
index range of the value sort order.
sliceIndex
range
index range of the value sort order.stream
undocumented
stream
streamRange
Returns a Stream of sorted values of this collection within the given keyRange
.
streamRange
keyRange
.Definition
streamRange(range: Range<T>, options?: {
reversed?: boolean;
}):
Stream
<T>;
Parameters
Name | Type | Description |
---|---|---|
range | Range<T> | |
options | { reversed?: boolean; } | (optional) an object containing the following properties: - reversed: (default: false) when true will reverse the stream element order |
const m = SortedSet.of('b', 'd', 'a', 'c');
console.log(m.streamRange({ start: 'b', end: 'c' }).toArray())
// => ['b', 'c']
streamSliceIndex
Returns a Stream of sorted values of this collection within the given range
index range.
streamSliceIndex
range
index range.Definition
streamSliceIndex(range: IndexRange, options?: {
reversed?: boolean;
}):
Stream
<T>;
Parameters
Name | Type | Description |
---|---|---|
range | IndexRange | the range of values to include in the stream |
options | { reversed?: boolean; } | (optional) an object containing the following properties: - reversed: (default: false) when true will reverse the stream element order |
const m = SortedSet.of('b', 'd', 'a', 'c');
console.log(m.streamSliceIndex({ start: 1, amount: 2 }).toArray())
// => ['b', 'c']
take
Returns a SortedSet containing the the first amount
of value of this SortedSet.
take
amount
of value of this SortedSet.Definition
take(amount: number):
SortedSet
<T>;
Parameters
Name | Type | Description |
---|---|---|
amount | number | the amount of elements to keep |
a negative amount
takes the last values instead of the first, e.g. -2 is the last 2 elements
const m = SortedSet.of('b', 'd', 'a', 'c').asNormal();
console.log(m.take(2).toArray())
// => ['a', 'b']
console.log(m.take(-2).toArray())
// => ['c', 'd']