interface VariantMultiSetBase<T,Tp>
undocumented
Companion namespace: VariantMultiSetBase
Extends: FastIterable<T>
Implemented by: MultiSetBase<T,Tp>, VariantMultiSetBase.NonEmpty<T,Tp>
Type parameters
| Name | Constraints | Default | Description |
|---|---|---|---|
| T | undocumented | ||
| Tp | VariantMultiSetBase.Types | VariantMultiSetBase.Types | undocumented |
Properties
countMap
Returns the Map representation of this collection.
countMapisEmpty
Returns true if the collection is empty.
isEmptyDefinition
readonly isEmpty: boolean;
HashMultiSet.empty<number>().isEmpty // => true
HashMultiSet.of(1, 2, 2).isEmpty // => false
size
Returns the number of values in the collection.
sizeDefinition
readonly size: number;
HashMultiSet.of(1, 2).size // => 2
HashMultiSet.of(1, 2, 2).size // => 3
sizeDistinct
Returns the number of distinct values in the collection.
sizeDistinctDefinition
readonly sizeDistinct: number;
HashMultiSet.of(1, 2).sizeDistinct // => 2
HashMultiSet.of(1, 2, 2).sizeDistinct // => 2
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.assumeNonEmpty
Returns the collection as a .NonEmpty type
assumeNonEmptyDefinition
assumeNonEmpty(): WithElem<Tp, T>['nonEmpty'];
RimbuError.EmptyCollectionAssumedNonEmptyError if the collection is empty
HashMultiSet.empty<number>().assumeNonEmpty() // => throws
const m: HashMultiSet<number> = HashMultiSet.of(1, 2)
const m2: HashMultiSet.NonEmpty<number> = m // => compiler error
const m3: HashMultiSet.NonEmpty<number> = m.assumeNonEmpty()
returns reference to this collection
count
Returns the amount of occurrances of the given value in the collection.
countvalue in the collection.filterEntries
Returns the collection containing only those values for which the given pred function returns true.
filterEntriespred function returns true.Definitions
filterEntries<TF extends T>(pred: (entry: readonly [T, number], index: number) => entry is [TF, number], options?: {
negate?: false | undefined;
}): WithElem<Tp, TF>['normal'];
filterEntries<TF extends T>(pred: (entry: readonly [T, number], index: number) => entry is [TF, number], options: {
negate: true;
}): WithElem<Tp, Exclude<T, TF>>['normal'];
filterEntries(pred: (entry: readonly [T, number], index: number) => boolean, options?: {
negate?: boolean;
}): WithElem<Tp, T>['normal'];
Type parameters
| Name | Constraints | Description |
|---|---|---|
| TF | T |
Parameters
| Name | Type | Description |
|---|---|---|
pred | (entry: readonly [T, number], index: number) => entry is [TF, number] | a predicate function receiving: - entry: the next entry consisting of the value and its count- index: the entry index- halt: a function that, when called, ensures no next entries 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
HashMultiSet.of(1, 2, 2, 3)
.filterEntries(entry => entry[1] > 1)
.toArray()
// => [[2, 2]]
forEach
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 value, receiving: - value: the next value- index: the index of the value- halt: a function that, if called, ensures that no new values are passed |
options | {state?: TraverseState;} | (optional) an object containing the following properties: - state: (optional) the traversal state |
HashMultiSet.of(1, 2, 2, 3).forEach((entry, i, halt) => {
console.log(entry)
if (i >= 1) halt()
})
// => logs [1, 1] [2, 2]
has
Returns true if the given value exists in the collection.
hasvalue exists in the collection.nonEmpty
Returns true if there is at least one entry in the collection, and instructs the compiler to treat the collection as a .NonEmpty type.
nonEmptyDefinition
nonEmpty(): this is WithElem<Tp, T>['nonEmpty'];
const m: HashMultiSet<number> = HashMultiSet.of(1, 2, 2)
m.stream().first(0) // compiler allows fallback value since the Stream may be empty
if (m.nonEmpty()) {
m.stream().first(0) // compiler error: fallback value not allowed since Stream is not empty
}
remove
Returns the collection where the given amount (default: 'ALL') of the given value are removed.
removeamount (default: 'ALL') of the given value are removed.Definition
remove<U = T>(value: RelatedTo<T, U>, options?: {
amount?: number | 'ALL';
}): WithElem<Tp, T>['normal'];
Type parameters
| Name | Default | Description |
|---|---|---|
| U | T |
Parameters
| Name | Type | Description |
|---|---|---|
value | RelatedTo<T, U> | the value to remove |
options | {amount?: number | 'ALL';} | (optional) an object containing the following properties: - amount: (default: 'ALL') the amount of values to remove, or 'ALL' to remove all values. |
const m = HashMultiSet.of(1, 2, 2)
m.remove(5).toArray() // => [1, 2, 2]
m.remove(2).toArray() // => [1]
m.remove(2, 1).toArray() // => [1, 2]
removeAllEvery
Returns the collection where for every value from given values StreamSource, all values in the collection are removed.
removeAllEveryvalues StreamSource, all values in the collection are removed.Definition
removeAllEvery<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. |
const m = HashMultiSet.of(1, 2, 2)
m.removeAllEvery([5, 6]).toArray() // => [1, 2, 2]
m.removeAllEvery([2, 3]).toArray() // => [1]
removeAllSingle
Returns the collection where every single value from given values StreamSource is removed.
removeAllSinglevalues StreamSource is removed.Definition
removeAllSingle<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. |
const m = HashMultiSet.of(1, 2, 2)
m.removeAllSingle([5, 6]).toArray() // => [1, 2, 2]
m.removeAllSingle([2, 3]).toArray() // => [1, 2]
m.removeAllSingle([2, 3, 2]).toArray() // => [1]
stream
Returns a Stream containing all values of this collection.
streamstreamDistinct
Returns a Stream containing all distinct values of this collection.
streamDistincttoArray
Returns an array containing all values in this collection.
toArrayDefinition
toArray(): T[];
HashMultiSet.of(1, 2, 2).toArray() // => [1, 2, 2]
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
toJSON
Returns a JSON representation of this collection.
toJSON