Skip to main content

interface OrderedSortedSet.NonEmpty<T>

A non-empty type-invariant immutable Ordered SortedSet of value type T. In the Set, there are no duplicate values. See the Set documentation and the OrderedSortedSet API documentation

Extends: Streamable.NonEmpty<T>, OrderedSetBase.NonEmpty<T,Tp>, OrderedSortedSet<T>

Type parameters

NameDescription
Tthe value type
note
  • The OrderedSortedSet keeps the insertion order of values, thus iterators and stream will also reflect this order.
    - The OrderedSortedSet wraps around a SortedSet instance, thus has the same time complexity as the SortedSet.
    - The OrderedSortedSet keeps the key insertion order in a List, thus its space complexity is higher than a regular SortedSet.
example
const s1 = OrderedSortedSet.empty<string>()
const s2 = OrderedSortedSet.of('a', 'b', 'c')

Properties

context

Returns the context associated to this collection instance.

Definition

readonly context: WithElem<Tp, T>['context'];

Overrides

RSetBase.context

isEmpty

Returns false since this collection is known to be non-empty

Definition

readonly isEmpty: false;

example
HashSet.of(1, 2, 3).isEmpty   // => false

Overrides

VariantSetBase.isEmptyNonEmpty.isEmpty

order

Returns a non-empty List instance containing the order of the elements.

Definition

readonly order: List.NonEmpty<T>;

example
const s = OrderedHashSet.of('b', 'a', 'c')
console.log(s.order.toArray())
// => ['b', 'a', 'c']

Overrides

NonEmpty.orderOrderedSetBase.order

size

Returns the number of values in the collection.

Definition

readonly size: number;

Overrides

VariantSetBase.size

sourceSet

Returns the contained non-empty Set instance.

Definition

readonly sourceSet: WithElem<Tp, T>['sourceSetNonEmpty'];

example
const s = OrderedHashSet.of('b', 'a', 'c')
console.log(m.sourceSet.toString())
// => HashSet('a', 'b', 'c')

Overrides

NonEmpty.sourceSetOrderedSetBase.sourceSet

Methods

[Symbol.iterator]

Returns a FastIterator instance used to iterate over the values of this Iterable.

Definition

[Symbol.iterator](): FastIterator<T>;

Overrides

FastIterable.[Symbol.iterator]

add

Returns the collection with given value added.

Definition

add(value: T): WithElem<Tp, T>['nonEmpty'];

Parameters

NameTypeDescription
valueTthe value to add
example
HashSet.of(1, 2, 3).add(10).toArray()   // => [1, 2, 3, 10]

Overrides

RSetBase.add, NonEmpty.add

addAll

Returns the collection with the values in given values StreamSource added.

Definition

addAll(values: StreamSource<T>): WithElem<Tp, T>['nonEmpty'];

Parameters

NameTypeDescription
valuesStreamSource<T>a StreamSource containing values to add
example
HashSet.of(1, 2, 3).addAll(10, 11).toArray()   // => [1, 2, 3, 10, 11]

Overrides

RSetBase.addAll, NonEmpty.addAll

asNormal

Returns this collection typed as a 'possibly empty' collection.

Definition

asNormal(): WithElem<Tp, T>['normal'];

example
HashSet.of(1, 2).asNormal();  // type: HashSet<number>

Overrides

NonEmpty.asNormal

assumeNonEmpty

Returns a self reference since this collection is known to be non-empty.

Definition

assumeNonEmpty(): this;

example
const m = HashSet.of(1, 2, 3);
m === m.assumeNonEmpty() // => true

Overrides

VariantSetBase.assumeNonEmpty, NonEmpty.assumeNonEmpty

difference

Returns a collection where each value of given other StreamSource is removed from this collection.

Definition

difference<U = T>(other: StreamSource<RelatedTo<T, U>>): WithElem<Tp, T>['normal'];

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
otherStreamSource<RelatedTo<T, U>>a StreamSource containing values
example
HashSet.of(1, 2, 3).difference(HashSet.of(1, 3)).toArray()  // => [2]

Overrides

VariantSetBase.difference

filter

Returns a collection containing only those entries that satisfy given pred 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

NameConstraintsDescription
TFT

Parameters

NameTypeDescription
pred(value: T, index: number, halt: () => void) => value is TFa 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
note

if the predicate is a type guard, the return type is automatically inferred

example
HashSet.of(1, 2, 3).filter(value < 3).toArray()
// => [1, 2]

Overrides

VariantSetBase.filter

forEach

Performs given function f 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

NameTypeDescription
f(value: T, index: number, halt: () => void) => voidthe 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;
  }
example
HashSet.of(1, 2, 3).forEach((value, i, halt) => {
console.log([value, i]);
if (i >= 1) halt();
})
// => logs [1, 0] [2, 1]
note

O(N)

Overrides

VariantSetBase.forEach

has

Returns true if given value is in the collection.

Definition

has<U = T>(value: RelatedTo<T, U>): boolean;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valueRelatedTo<T, U>the value to look for
example
HashSet.of(1, 2, 3).has(2)  // => true
HashSet.of(1, 2, 3).has(10) // => false

Overrides

VariantSetBase.has

intersect

Returns a collection containing values that are both in this collection, and in the given other StreamSource.

Definition

intersect<U = T>(other: StreamSource<RelatedTo<T, U>>): WithElem<Tp, T>['normal'];

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
otherStreamSource<RelatedTo<T, U>>a StreamSource containing values
example
HashSet.of(1, 2, 3).interface(HashSet.of(1, 3)).toArray()   // => [1, 3]

Overrides

VariantSetBase.intersect

nonEmpty

Returns true since this collection is know to be non-empty

Definition

nonEmpty(): true;

example
HashSet.of(1, 2, 3).nonEmpty()   // => true

Overrides

VariantSetBase.nonEmpty, NonEmpty.nonEmpty

remove

Returns the collection with given value removed.

Definition

remove<U = T>(value: RelatedTo<T, U>): WithElem<Tp, T>['normal'];

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valueRelatedTo<T, U>the value to remove
example
const s = HashSet.of(1, 2, 3)
s.remove(2).toArray() // => [1, 3]
s.remove(10).toArray() // => [1, 2, 3]

Overrides

VariantSetBase.remove

removeAll

Returns the collection with all values in the given values StreamSource removed.

Definition

removeAll<U = T>(values: StreamSource<RelatedTo<T, U>>): WithElem<Tp, T>['normal'];

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valuesStreamSource<RelatedTo<T, U>>a StreamSource containing values to remove
example
HashSet.of(1, 2, 3).removeAll([1, 3]).toArray()
// => [2]

Overrides

VariantSetBase.removeAll

stream

undocumented

Definition

stream(): Stream.NonEmpty<T>;

Overrides

NonEmpty.stream

symDifference

Returns a collection of the values that are either in this collection or in the other StreamSource, but not in both.

Definition

symDifference(other: StreamSource<T>): WithElem<Tp, T>['normal'];

Parameters

NameTypeDescription
otherStreamSource<T>a StreamSource containing values
example
HashSet.of(1, 2, 3).symDifference([2, 4]).toArray()
// => [1, 3, 4]

Overrides

RSetBase.symDifference

toArray

Returns a non-empty array containing all values in this collection.

Definition

toArray(): ArrayNonEmpty<T>;

example
HashSet.of(1, 2, 3).toArray()   // => [1, 2, 3]
note

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

VariantSetBase.toArray, NonEmpty.toArray

toBuilder

Returns a builder object containing the values of this collection.

Definition

toBuilder(): WithElem<Tp, T>['builder'];

example
const builder: HashSet.Builder<number> = HashSet.of(1, 2, 3).toBuilder()

Overrides

RSetBase.toBuilder

toJSON

Returns a JSON representation of this collection.

Definition

toJSON(): ToJSON<T[]>;

example
HashSet.of(1, 2, 3).toJSON()   // => { dataType: 'HashSet', value: [1, 2, 3] }

Overrides

VariantSetBase.toJSON

toString

Returns a string representation of this collection.

Definition

toString(): string;

example
HashSet.of(1, 2, 3).toString()   // => HashSet(1, 2, 3)

Overrides

VariantSetBase.toString

union

Returns a collection containing all values from this collection and all values of given other StreamSource.

Definition

union(other: StreamSource<T>): WithElem<Tp, T>['nonEmpty'];

Parameters

NameTypeDescription
otherStreamSource<T>a StreamSource containing values
example
HashSet.of(1, 2, 3).union(HashSet.of(2, 4, 6)).toArray()
// => [1, 2, 3, 4, 6]

Overrides

RSetBase.union, NonEmpty.union