namespace SortedMultiSet
A type-invariant immutable MultiSet of value type T. In the MultiSet, each value can occur multiple times. See the MultiSet documentation and the SortedMultiSet API documentation
Companion interface: SortedMultiSet<T>
Interfaces
Name | Description |
---|---|
SortedMultiSet.Builder<T> | A mutable SortedMultiSet builder used to efficiently create new immutable instances. See the MultiSet documentation and the SortedMultiSet.Builder API documentation |
SortedMultiSet.Context<UT> | A context instance for an SortedMultiSet that acts as a factory for every instance of this type of collection. |
SortedMultiSet.NonEmpty<T> | A type-invariant immutable MultiSet of value type T. In the MultiSet, each value can occur multiple times. See the MultiSet documentation and the SortedMultiSet API documentation |
SortedMultiSet.Types | Utility interface that provides higher-kinded types for this collection. |
Static Methods
builder
Returns an empty builder instance for this type of collection and context.
builder
createContext
Returns a new HashMultiSet context instance based on the given options
.
createContext
options
.Definition
createContext<UT>(options?: {
countMapContext?:
SortedMap.Context
<UT>;
}):
SortedMultiSet.Context
<UT>;
Type parameters
Name | Description |
---|---|
UT | the upper element type for which the context can create instances |
Parameters
Name | Type | Description |
---|---|---|
options | { countMapContext?: SortedMap.Context <UT>; } | (optional) an object containing the following properties: - countMapContext: (optional) the map context to use for key to count mapping |
defaultContext
Returns the default context for HashMultiSet.
defaultContext
Definition
defaultContext<UT>():
SortedMultiSet.Context
<UT>;
Type parameters
Name | Description |
---|---|
UT | the upper element type for which the context can create instances |
empty
Returns the (singleton) empty instance of this type and context with given key and value types.
empty
from
Returns an immutable multimap of this type and context, containing the values in the given sources
StreamSource
.
from
sources
StreamSource
.Definitions
from<T extends UT>(...sources:
ArrayNonEmpty
<
StreamSource.NonEmpty
<T>>):
WithElem
<Tp, T>['nonEmpty'];
from<T extends UT>(...sources:
ArrayNonEmpty
<
StreamSource
<T>>):
WithElem
<Tp, T>['normal'];
Type parameters
Name | Constraints | Description |
---|---|---|
T | UT |
Parameters
Name | Type | Description |
---|---|---|
sources | ArrayNonEmpty < StreamSource.NonEmpty <T>> | a non-empty array of StreamSource instances containing values to add |
HashMultiSet.from([1, 2], [2, 3, 4]).toArray() // => [1, 2, 2, 3, 4]
Overrides
of
Returns an immutable multimap of this collection type and context, containing the given values
.
of
values
.Definition
of<T extends UT>(...values:
ArrayNonEmpty
<T>):
WithElem
<Tp, T>['nonEmpty'];
Type parameters
Name | Constraints | Description |
---|---|---|
T | UT |
Parameters
Name | Type | Description |
---|---|---|
values | ArrayNonEmpty <T> | a non-empty array of vslues |
HashMultiSet.of(1, 2, 2) // => HashMultiSet.NonEmpty<number>
Overrides
reducer
Returns a Reducer
that appends received items to a MultiSet and returns the MultiSet as a result. When a source
is given, the reducer will first create a MultiSet from the source, and then add elements to it.
reducer
Reducer
that appends received items to a MultiSet and returns the MultiSet as a result. When a source
is given, the reducer will first create a MultiSet from the source, and then add elements to it.Definition
reducer<T extends UT>(source?:
StreamSource
<T>): Reducer<T,
WithElem
<Tp, T>['normal']>;
Type parameters
Name | Constraints | Description |
---|---|---|
T | UT |
Parameters
Name | Type | Description |
---|---|---|
source | StreamSource <T> | (optional) an initial source of elements to add to |
const someList = [1, 2, 3];
const result = Stream.range({ start: 20, amount: 5 }).reduce(SortedMultiSet.reducer(someList))
result.toArray() // => [1, 2, 3, 20, 21, 22, 23, 24]
uses a MultiSet builder under the hood. If the given source
is a MultiSet in the same context, it will directly call .toBuilder()
.