Collection

Collection

The collection class, ported from Eris
Hold a bunch of values

Constructor

# new Collection(baseObject, limitopt)

Construct a Collection

Parameters:
NameTypeAttributesDescription
baseObjectClass

The base class for all items

limitNumber<optional>

Max number of items to hold

Properties
NameTypeAttributesDescription
baseObjectClass

The base class for all items

limitNumber<nullable>

Max number of items to hold

Since:
  • v2.5.2-beta.1

Extends

  • Map

Methods

# add(obj, extraopt, replaceopt) → {Class}

Add an object

Parameters:
NameTypeAttributesDescription
objObject

The object data

Properties
NameTypeDescription
idString

The ID of the object

extraClass<optional>

An extra parameter the constructor may need

replaceBoolean<optional>

Whether to replace an existing object with the same ID

Returns:

The existing or newly created object

Type
Class

# every(func) → {Boolean}

Returns true if all elements satisfy the condition

Parameters:
NameTypeDescription
funcfunction

A function that takes an object and returns true or false

Returns:

Whether or not all elements satisfied the condition

Type
Boolean

# filter(func) → {Array.<Class>}

Return all the objects that make the function evaluate true

Parameters:
NameTypeDescription
funcfunction

A function that takes an object and returns true if it matches

Returns:

An array containing all the objects that matched

Type
Array.<Class>

# find(func) → (nullable) {Class}

Return the first object to make the function evaluate true

Parameters:
NameTypeDescription
funcfunction

A function that takes an object and returns true if it matches

Returns:

The first matching object, or undefined if no match

Type
Class

# map(func) → {Array}

Return an array with the results of applying the given function to each element

Parameters:
NameTypeDescription
funcfunction

A function that takes an object and returns something

Returns:

An array containing the results

Type
Array

# random() → (nullable) {Class}

Get a random object from the Collection

Returns:

The random object, or undefined if there is no match

Type
Class

# reduce(func, initialValueopt) → {any}

Returns a value resulting from applying a function to every element of the collection

Parameters:
NameTypeAttributesDescription
funcfunction

A function that takes the previous value and the next item and returns a new value

initialValueany<optional>

The initial value passed to the function

Returns:

The final result

Type
any

# remove(obj) → (nullable) {Class}

Remove an object

Parameters:
NameTypeDescription
objObject

The object

Properties
NameTypeDescription
idString

The ID of the object

Returns:

The removed object, or null if nothing was removed

Type
Class

# some(func) → {Boolean}

Returns true if at least one element satisfies the condition

Parameters:
NameTypeDescription
funcfunction

A function that takes an object and returns true or false

Returns:

Whether or not at least one element satisfied the condition

Type
Boolean

# update(obj, extraopt, replaceopt) → {Class}

Update an object

Parameters:
NameTypeAttributesDescription
objObject

The updated object data

Properties
NameTypeDescription
idString

The ID of the object

extraClass<optional>

An extra parameter the constructor may need

replaceBoolean<optional>

Whether to replace an existing object with the same ID

Returns:

The updated object

Type
Class