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: SortedSet.NonEmpty<T>
Type parameters
| Name | Description |
|---|---|
| T | the value type |
- The
SortedSetkeeps the inserted values in sorted order according to the context'scompCompinstance.
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.
dropamount 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']
findIndex
Returns the index of the given value in the SortedSet, or -1 if the value is not present.
findIndexgetAtIndex
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.
getAtIndexDefinitions
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.
maxmin
Returns the minimum value of the SortedSet, or a fallback value (default: undefined) if the SortedSet is empty.
minslice
Returns a SortedSet containing only those values that are within the given keyRange.
slicekeyRange.sliceIndex
Returns a SortedSet containing only those values that are within the given range index range of the value sort order.
sliceIndexrange index range of the value sort order.stream
undocumented
streamstreamRange
Returns a Stream of sorted values of this collection within the given keyRange.
streamRangekeyRange.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.
streamSliceIndexrange 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.
takeamount 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']