interface VariantSet.NonEmpty<T>
A non-empty type-variant immutable Set of value type T. In the Set, there are no duplicate values. See the Set documentation and the VariantSet API documentation
Extends: VariantSet<T>
, VariantSetBase.NonEmpty<T,Tp>
Type parameters
Name | Description |
---|---|
T | the value type |
Type-variance means that both the value type can be widened in a type-safe way without casting. @note As a consequence of being variant, the type does not contain methods that (can) add new elements to the collection.
Properties
isEmpty
Returns false since this collection is known to be non-empty
isEmpty
size
Returns the number of values in the collection.
size
Methods
[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
.asNormal
Returns this collection typed as a 'possibly empty' collection.
asNormal
assumeNonEmpty
Returns a self reference since this collection is known to be non-empty.
assumeNonEmpty
difference
Returns a collection where each value of given other
StreamSource
is removed from this collection.
difference
other
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 StreamSource containing values |
HashSet.of(1, 2, 3).difference(HashSet.of(1, 3)).toArray() // => [2]
Overrides
filter
Returns a collection containing only those entries that satisfy given pred
predicate.
filter
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
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
forEach
Performs given function f
for each value of the collection, using given state
as initial traversal state.
forEach
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
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
has
Returns true if given value
is in the collection.
has
value
is in the collection.intersect
Returns a collection containing values that are both in this collection, and in the given other
StreamSource
.
intersect
other
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 StreamSource containing values |
HashSet.of(1, 2, 3).interface(HashSet.of(1, 3)).toArray() // => [1, 3]
Overrides
nonEmpty
Returns true since this collection is know to be non-empty
nonEmpty
remove
Returns the collection with given value
removed.
remove
value
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.
removeAll
values
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 StreamSource containing values to remove |
HashSet.of(1, 2, 3).removeAll([1, 3]).toArray()
// => [2]
Overrides
stream
Returns a non-empty Stream containing all values of this collection.
stream
Definition
stream():
Stream.NonEmpty
<T>;
HashSet.of(1, 2, 3).stream().toArray() // => [1, 2, 3]
Overrides
toArray
Returns a non-empty array containing all values in this collection.
toArray
Definition
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
toJSON
Returns a JSON representation of this collection.
toJSON