interface SortedSet.NonEmpty<T>
A non-empty 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
Extends: Streamable.NonEmpty<T>, RSetBase.NonEmpty<T,Tp>, SortedSet<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')
Properties
context
Returns the context associated to this collection instance.
contextcontext associated to this collection instance.isEmpty
Returns false since this collection is known to be non-empty
isEmptysize
Returns the number of values in the collection.
sizeMethods
[Symbol.iterator]
Returns a FastIterator instance used to iterate over the values of this Iterable.
[Symbol.iterator]FastIterator instance used to iterate over the values of this Iterable.add
Returns the collection with given value added.
addvalue added.addAll
Returns the collection with the values in given values StreamSource added.
addAllvalues StreamSource added.Definition
addAll(values: StreamSource<T>): WithElem<Tp, T>['nonEmpty'];
Parameters
| Name | Type | Description | 
|---|---|---|
| values | StreamSource<T> | a StreamSourcecontaining values to add | 
HashSet.of(1, 2, 3).addAll(10, 11).toArray()   // => [1, 2, 3, 10, 11]
Overrides
asNormal
Returns this collection typed as a 'possibly empty' collection.
asNormalassumeNonEmpty
Returns a self reference since this collection is known to be non-empty.
assumeNonEmptydifference
Returns a collection where each value of given other StreamSource is removed from this collection.
differenceother StreamSource is removed from this collection.Definition
difference<U = T>(other: StreamSource<RelatedTo<T, U>>): WithElem<Tp, T>['normal'];
Type parameters
| Name | Default | Description | 
|---|---|---|
| U | T | 
Parameters
| Name | Type | Description | 
|---|---|---|
| other | StreamSource<RelatedTo<T, U>> | a StreamSourcecontaining values | 
HashSet.of(1, 2, 3).difference(HashSet.of(1, 3)).toArray()  // => [2]
Overrides
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']
Overrides
filter
Returns a collection containing only those entries that satisfy given pred predicate.
filterpred predicate.Definitions
filter<TF extends T>(pred: (value: T, index: number, halt: () => void) => value is TF, options?: {
    negate?: false | undefined;
  }): WithElem<Tp, TF>['normal'];
filter<TF extends T>(pred: (value: T, index: number, halt: () => void) => value is TF, options: {
    negate: true;
  }): WithElem<Tp, Exclude<T, TF>>['normal'];
filter(pred: (value: T, index: number, halt: () => void) => boolean, options?: {
    negate?: boolean;
  }): WithElem<Tp, T>['normal'];
Type parameters
| Name | Constraints | Description | 
|---|---|---|
| TF | T | 
Parameters
| Name | Type | Description | 
|---|---|---|
| pred | (value: T, index: number, halt: () => void) => value is TF | a predicate function receiving: - value: the next value- index: the entry index- halt: a function that, when called, ensures no next elements are passed | 
| options | {negate?: false | undefined;} | (optional) an object containing the following properties: - negate: (default: false) when true will negate the predicate | 
if the predicate is a type guard, the return type is automatically inferred
HashSet.of(1, 2, 3).filter(value < 3).toArray()
// => [1, 2]
Overrides
findIndex
Returns the index of the given value in the SortedSet, or -1 if the value is not present.
findIndexforEach
Performs given function f for each value of the collection, using given state as initial traversal state.
forEachf for each value of the collection, using given state as initial traversal state.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;} | 
HashSet.of(1, 2, 3).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, 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'
Overrides
has
Returns true if given value is in the collection.
hasvalue is in the collection.intersect
Returns a collection containing values that are both in this collection, and in the given other StreamSource.
intersectother StreamSource.Definition
intersect<U = T>(other: StreamSource<RelatedTo<T, U>>): WithElem<Tp, T>['normal'];
Type parameters
| Name | Default | Description | 
|---|---|---|
| U | T | 
Parameters
| Name | Type | Description | 
|---|---|---|
| other | StreamSource<RelatedTo<T, U>> | a StreamSourcecontaining values | 
HashSet.of(1, 2, 3).interface(HashSet.of(1, 3)).toArray()   // => [1, 3]
Overrides
max
Returns the maximum value of the SortedSet.
maxmin
Returns the minimum value of the SortedSet.
minnonEmpty
Returns true since this collection is know to be non-empty
nonEmptyremove
Returns the collection with given value removed.
removevalue removed.Definition
remove<U = T>(value: RelatedTo<T, U>): WithElem<Tp, T>['normal'];
Type parameters
| Name | Default | Description | 
|---|---|---|
| U | T | 
Parameters
| Name | Type | Description | 
|---|---|---|
| value | RelatedTo<T, U> | the value to remove | 
const s = HashSet.of(1, 2, 3)
s.remove(2).toArray()   // => [1, 3]
s.remove(10).toArray()  // => [1, 2, 3]
Overrides
removeAll
Returns the collection with all values in the given values StreamSource removed.
removeAllvalues StreamSource removed.Definition
removeAll<U = T>(values: StreamSource<RelatedTo<T, U>>): WithElem<Tp, T>['normal'];
Type parameters
| Name | Default | Description | 
|---|---|---|
| U | T | 
Parameters
| Name | Type | Description | 
|---|---|---|
| values | StreamSource<RelatedTo<T, U>> | a StreamSourcecontaining values to remove | 
HashSet.of(1, 2, 3).removeAll([1, 3]).toArray()
// => [2]
Overrides
slice
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.Definition
sliceIndex(range: IndexRange): SortedSet<T>;
Parameters
| Name | Type | Description | 
|---|---|---|
| range | IndexRange | an IndexRangedefining the sort order indices to include. | 
const m = SortedSet.of('b', 'd', 'a', 'c').asNormal();
console.log(m.sliceIndex({ start: 1, amount: 2 }).toArray())
// => ['b', 'c']
Overrides
stream
undocumented
streamDefinition
stream(options?: {
      reversed?: boolean;
    }): Stream.NonEmpty<T>;
Parameters
| Name | Type | Description | 
|---|---|---|
| options | {reversed?: boolean;} | 
Overrides
streamRange
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']
Overrides
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']
Overrides
symDifference
Returns a collection of the values that are either in this collection or in the other StreamSource, but not in both.
symDifferenceother StreamSource, but not in both.Definition
symDifference(other: StreamSource<T>): WithElem<Tp, T>['normal'];
Parameters
| Name | Type | Description | 
|---|---|---|
| other | StreamSource<T> | a StreamSourcecontaining values | 
HashSet.of(1, 2, 3).symDifference([2, 4]).toArray()
// => [1, 3, 4]
Overrides
take
undocumented
taketoArray
Returns a non-empty array containing all values in this collection.
toArrayDefinition
toArray(): ArrayNonEmpty<T>;
HashSet.of(1, 2, 3).toArray()   // => [1, 2, 3]
O(log(N)) @note it is safe to mutate the returned array, however, the array elements are not copied, thus should be treated as read-only
Overrides
toBuilder
Returns a builder object containing the values of this collection.
toBuildertoJSON
Returns a JSON representation of this collection.
toJSONtoString
Returns a string representation of this collection.
toStringunion
Returns a collection containing all values from this collection and all values of given other StreamSource.
unionother StreamSource.Definition
union(other: StreamSource<T>): WithElem<Tp, T>['nonEmpty'];
Parameters
| Name | Type | Description | 
|---|---|---|
| other | StreamSource<T> | a StreamSourcecontaining values | 
HashSet.of(1, 2, 3).union(HashSet.of(2, 4, 6)).toArray()
// => [1, 2, 3, 4, 6]