Class: Collection<K, V>
Extends
Collection
<K
,V
>
Type Parameters
• K
• V
Constructors
new Collection()
new Collection<
K
,V
>(entries
?):Collection
<K
,V
>
Parameters
• entries?: readonly readonly [K
, V
][]
Returns
Collection
<K
, V
>
Inherited from
BaseCollection<K, V>.constructor
new Collection()
new Collection<
K
,V
>(iterable
?):Collection
<K
,V
>
Parameters
• iterable?: Iterable
<readonly [K
, V
]>
Returns
Collection
<K
, V
>
Inherited from
BaseCollection<K, V>.constructor
Properties
[toStringTag]
readonly
[toStringTag]:string
Inherited from
BaseCollection.[toStringTag]
constructor
constructor:
CollectionConstructor
The initial value of Object.prototype.constructor is the standard built-in Object constructor.
Inherited from
BaseCollection.constructor
size
readonly
size:number
Inherited from
BaseCollection.size
[species]
readonly
static
[species]:MapConstructor
Inherited from
BaseCollection.[species]
Methods
[iterator]()
[iterator]():
IterableIterator
<[K
,V
]>
Returns an iterable of entries in the map.
Returns
IterableIterator
<[K
, V
]>
Inherited from
BaseCollection.[iterator]
at()
at(
index
):V
Identical to Array.at(). Returns the item at a given index, allowing for positive and negative integers. Negative integers count back from the last item in the collection.
Parameters
• index: number
The index of the element to obtain
Returns
V
Inherited from
BaseCollection.at
clear()
clear():
void
Returns
void
Inherited from
BaseCollection.clear
clone()
clone():
Collection
<K
,V
>
Creates an identical shallow copy of this collection.
Returns
Collection
<K
, V
>
Example
const newColl = someColl.clone();
Inherited from
BaseCollection.clone
concat()
concat(...
collections
):Collection
<K
,V
>
Combines this collection with others into a new collection. None of the source collections are modified.
Parameters
• ...collections: ReadonlyCollection
<K
, V
>[]
Collections to merge
Returns
Collection
<K
, V
>
Example
const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
Inherited from
BaseCollection.concat
delete()
delete(
key
):boolean
Parameters
• key: K
Returns
boolean
true if an element in the Map existed and has been removed, or false if the element does not exist.
Inherited from
BaseCollection.delete
difference()
difference<
T
>(other
):Collection
<K
,V
|T
>
The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.
Type Parameters
• T
Parameters
• other: ReadonlyCollection
<K
, T
>
The other Collection to filter against
Returns
Collection
<K
, V
| T
>
Inherited from
BaseCollection.difference
each()
each(fn)
each(
fn
):this
Identical to Map.forEach(), but returns the collection instead of undefined.
Parameters
• fn
Function to execute for each element
Returns
this
Example
collection
.each(user => console.log(user.username))
.filter(user => user.bot)
.each(user => console.log(user.username));
Inherited from
BaseCollection.each
each(fn, thisArg)
each<
T
>(fn
,thisArg
):this
Type Parameters
• T
Parameters
• fn
• thisArg: T
Returns
this
Inherited from
BaseCollection.each
ensure()
ensure(
key
,defaultValueGenerator
):V
Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.
Parameters
• key: K
The key to get if it exists, or set otherwise
• defaultValueGenerator
A function that generates the default value
Returns
V
Example
collection.ensure(guildId, () => defaultGuildConfig);
Inherited from
BaseCollection.ensure
entries()
entries():
IterableIterator
<[K
,V
]>
Returns an iterable of key, value pairs for every entry in the map.
Returns
IterableIterator
<[K
, V
]>
Inherited from
BaseCollection.entries
equals()
equals(
collection
):boolean
Checks if this collection shares identical items with another. This is different to checking for equality using equal-signs, because the collections may be different objects, but contain the same data.
Parameters
• collection: ReadonlyCollection
<K
, V
>
Collection to compare with
Returns
boolean
Whether the collections have identical contents
Inherited from
BaseCollection.equals
every()
every(fn)
every<
K2
>(fn
):this is Collection<K2, V>
Checks if all items passes a test. Identical in behavior to Array.every().
Type Parameters
• K2
Parameters
• fn
Function used to test (should return a boolean)
Returns
this is Collection<K2, V>
Example
collection.every(user => !user.bot);
Inherited from
BaseCollection.every
every(fn)
every<
V2
>(fn
):this is Collection<K, V2>
Type Parameters
• V2
Parameters
• fn
Returns
this is Collection<K, V2>
Inherited from
BaseCollection.every
every(fn)
every(
fn
):boolean
Parameters
• fn
Returns
boolean
Inherited from
BaseCollection.every
every(fn, thisArg)
every<
This
,K2
>(fn
,thisArg
):this is Collection<K2, V>
Type Parameters
• This
• K2
Parameters
• fn
• thisArg: This
Returns
this is Collection<K2, V>
Inherited from
BaseCollection.every
every(fn, thisArg)
every<
This
,V2
>(fn
,thisArg
):this is Collection<K, V2>
Type Parameters
• This
• V2
Parameters
• fn
• thisArg: This
Returns
this is Collection<K, V2>
Inherited from
BaseCollection.every
every(fn, thisArg)
every<
This
>(fn
,thisArg
):boolean
Type Parameters
• This
Parameters
• fn
• thisArg: This
Returns
boolean
Inherited from
BaseCollection.every
filter()
filter(fn)
filter<
K2
>(fn
):Collection
<K2
,V
>
Identical to Array.filter(), but returns a Collection instead of an Array.
Type Parameters
• K2
Parameters
• fn
The function to test with (should return boolean)
Returns
Collection
<K2
, V
>
Example
collection.filter(user => user.username === 'Bob');
Inherited from
BaseCollection.filter
filter(fn)
filter<
V2
>(fn
):Collection
<K
,V2
>
Type Parameters
• V2
Parameters
• fn
Returns
Collection
<K
, V2
>
Inherited from
BaseCollection.filter
filter(fn)
filter(
fn
):Collection
<K
,V
>
Parameters
• fn
Returns
Collection
<K
, V
>
Inherited from
BaseCollection.filter
filter(fn, thisArg)
filter<
This
,K2
>(fn
,thisArg
):Collection
<K2
,V
>