Skip to main content

interface MultiSetBase.Builder<T,Tp>

undocumented

Implemented by: MultiSetBuilder<T,Tp,TpG>, HashMultiSet.Builder<T>, SortedMultiSet.Builder<T>, MultiSet.Builder<T>

Type parameters

NameConstraintsDefaultDescription
Tundocumented
TpMultiSetBase.TypesMultiSetBase.Typesundocumented

Properties

isEmpty

Returns true if there are no values in the builder.

Definition

readonly isEmpty: boolean;

example
HashMultiSet.of(1, 2, 2).toBuilder().isEmpty
// => false

size

Returns the amount of values in the builder.

Definition

readonly size: number;

example
HashMultiSet.of(1, 2, 2).toBuilder().size
// => 3

sizeDistinct

Returns the amount of distinct values in the builder.

Definition

readonly sizeDistinct: number;

example
HashMultiSet.of(1, 2, 2).toBuilder().sizeDistinct
// => 2

Methods

add

Adds given value to the builder.

Definition

add(value: T, amount?: number): boolean;

Parameters

NameTypeDescription
valueT
amountnumber
example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.add(2) // => true
s.add(3, 5) // => true
s.add(3, 0) // => false

addAll

Adds the values in given values StreamSource to the builder.

Definition

addAll(values: StreamSource<T>): boolean;

Parameters

NameTypeDescription
valuesStreamSource<T>
example
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.

Definition

addEntries(entries: StreamSource<readonly [T, number]>): boolean;

Parameters

NameTypeDescription
entriesStreamSource<readonly [T, number]>
example
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.

Definition

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

example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
const s2: HashMultiSet<number> = m.build()

count

Returns the amount of given value in the builder.

Definition

count<U = T>(value: RelatedTo<T, U>): number;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valueRelatedTo<T, U>the value to look for
example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.count(10) // => 0
s.count(2) // => 2

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 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
throws

RibuError.ModifiedBuilderWhileLoopingOverItError if the builder is modified while looping over it

example
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.

Definition

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

Type parameters

NameDefaultDescription
UT

Parameters

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

modifyCount

Changes the amount of given value in the builder according to the result of given update function.

Definition

modifyCount(value: T, update: (currentCount: number) => number): boolean;

Parameters

NameTypeDescription
valueTthe value of which to update the amount
update(currentCount: number) => number
note

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)

example
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.

Definition

remove<U = T>(value: RelatedTo<T, U>, amount?: number | 'ALL'): number;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valueRelatedTo<T, U>the value to remove
amountnumber | 'ALL'
example
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.

Definition

removeAllEvery<U = T>(values: StreamSource<RelatedTo<T, U>>): boolean;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valuesStreamSource<RelatedTo<T, U>>
example
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.

Definition

removeAllSingle<U = T>(values: StreamSource<RelatedTo<T, U>>): boolean;

Type parameters

NameDefaultDescription
UT

Parameters

NameTypeDescription
valuesStreamSource<RelatedTo<T, U>>
example
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.

Definition

setCount(value: T, amount: number): boolean;

Parameters

NameTypeDescription
valueTthe value for which to set the amount
amountnumber
note

if amount <= 0, the value will be removed

example
const s = HashMultiSet.of(1, 2, 2).toBuilder()
s.setCount(1, 1) // => false
s.setCount(1, 3) // => true