interface MultiSetBase.Builder<T,Tp>
undocumented
Implemented by: MultiSetBuilder<T,Tp,TpG>
, HashMultiSet.Builder<T>
, SortedMultiSet.Builder<T>
, MultiSet.Builder<T>
Type parameters
Name | Constraints | Default | Description |
---|---|---|---|
T | undocumented | ||
Tp | MultiSetBase.Types | MultiSetBase.Types | undocumented |
Properties
isEmpty
Returns true if there are no values in the builder.
isEmpty
size
Returns the amount of values in the builder.
size
sizeDistinct
Returns the amount of distinct values in the builder.
sizeDistinct
Definition
readonly sizeDistinct: number;
HashMultiSet.of(1, 2, 2).toBuilder().sizeDistinct
// => 2
Methods
add
Adds given value
to the builder.
add
value
to the builder.addAll
Adds the values in given values
StreamSource
to the builder.
addAll
values
StreamSource
to the builder.Definition
addAll(values:
StreamSource
<T>): boolean;
Parameters
Name | Type | Description |
---|---|---|
values | StreamSource <T> |
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.addAll(1, 3) // => false
s.addAll(2, 10) // => true
addEntries
Adds for each tuple of a value and amount in the given entries
, the amount of values to the builder.
addEntries
entries
, the amount of values to the builder.Definition
addEntries(entries:
StreamSource
<readonly [T, number]>): boolean;
Parameters
Name | Type | Description |
---|---|---|
entries | StreamSource <readonly [T, number]> |
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.addEntries([[1, 2], [2, 3]]) // => true
s.addEntries([[1, 0], [3, 0]]) // => false
build
Returns an immutable instance containing the values in this builder.
build
count
Returns the amount of given value
in the builder.
count
value
in the builder.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 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 |
RibuError.ModifiedBuilderWhileLoopingOverItError if the builder is modified while looping over it
HashMultiSet.of(1, 2, 2, 3).toBuilder().forEach((entry, i, halt) => {
console.log(entry)
if (i >= 1) halt()
})
// => logs [1, 1] [2, 2]
has
Returns true if the given value
is present in the builder.
has
value
is present in the builder.modifyCount
Changes the amount of given value
in the builder according to the result of given update
function.
modifyCount
value
in the builder according to the result of given update
function.Definition
modifyCount(value: T, update: (currentCount: number) => number): boolean;
Parameters
Name | Type | Description |
---|---|---|
value | T | the value of which to update the amount |
update | (currentCount: number) => number |
if the given value
does not exists, the update
function is called with 0. @note if the result of update
is <= 0, the value will be removed (or not added)
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.modifyCount(3, v => v) // => false
s.modifyCount(3, v => v + 1) // => true
s.modifyCount(2, v => v + 1) // => true
remove
Removes given amount
or all of given value
from the builder.
remove
amount
or all of given value
from the builder.Definition
remove<U = T>(value:
RelatedTo
<T, U>, amount?: number
|
'ALL'): number;
Type parameters
Name | Default | Description |
---|---|---|
U | T |
Parameters
Name | Type | Description |
---|---|---|
value | RelatedTo <T, U> | the value to remove |
amount | number | 'ALL' |
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.remove(10) // => 0
s.remove(1, 2) // => 1
s.remove(2, 2) // => 2
removeAllEvery
Removes every instance of the given values
from the builder.
removeAllEvery
values
from the builder.Definition
removeAllEvery<U = T>(values:
StreamSource
<
RelatedTo
<T, U>>): boolean;
Type parameters
Name | Default | Description |
---|---|---|
U | T |
Parameters
Name | Type | Description |
---|---|---|
values | StreamSource < RelatedTo <T, U>> |
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.removeAllEvery([10, 11]) // => false
s.removeAllEvery([1, 11]) // => true
removeAllSingle
Removes every single value in given values
from the builder.
removeAllSingle
values
from the builder.Definition
removeAllSingle<U = T>(values:
StreamSource
<
RelatedTo
<T, U>>): boolean;
Type parameters
Name | Default | Description |
---|---|---|
U | T |
Parameters
Name | Type | Description |
---|---|---|
values | StreamSource < RelatedTo <T, U>> |
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.removeAllSingle([10, 11]) // => false
s.removeAllSingle([1, 11]) // => true
setCount
Sets the amount of given value
in the collection to amount
.
setCount
value
in the collection to amount
.