Collection
ClassOn this page
Collection is an ordered id-keyed map used for caches. #collection matches :size().
Constructor
Collection.new(entries) The class table is callable, so Collection(entries) is the same as .new.
| Name | Type | Required | Behavior |
|---|---|---|---|
entries |
any |
required | Passed through to the implementation as written. |
local discord = require("discord")
local object = discord.Collection({})Methods
Collection:at()
#Performs at on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:at(index) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
index |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:at(index)Collection:clear()
#Performs clear on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:clear() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:clear()Collection:clone()
#Performs clone on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:clone() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:clone()Collection:combine()
#Performs combine on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:combine(other, collide) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
other |
any |
required | Passed through to the implementation as written. |
collide |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:combine(other, "123")Performs combine entries on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection.combineEntries(entries, combine) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
entries |
any |
required | Passed through to the implementation as written. |
combine |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
Collection.combineEntries(entries, combine)Collection:concat()
#Performs concat on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:concat(...) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
... |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:concat(...)Collection:delete()
#Permanently delete this resource through REST.
Signature
Collection:delete(key) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
key |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:delete(key)Collection:difference()
#Performs difference on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:difference(other) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
other |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:difference(other)Collection:each()
#Performs each on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:each(fn) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
fn |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:each(fn)Collection:ensure()
#Performs ensure on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:ensure(key, defaultValue) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
key |
any |
required | Passed through to the implementation as written. |
defaultValue |
any |
optional | Passed through to the implementation as written. |
Returns
any.
Example
local discord = require("discord")
-- object is a Collection
object:ensure(key, defaultValue)Collection:entries()
#Performs entries on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:entries() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:entries()Collection:equals()
#Return whether this Collection refers to the same resource as the argument.
Signature
Collection:equals(other) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
other |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:equals(other)Collection:every()
#Performs every on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:every(predicate) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
predicate |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:every(predicate)Collection:filter()
#Performs filter on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:filter(predicate) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
predicate |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:filter(predicate)Collection:find()
#Performs find on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:find(predicate) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
predicate |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:find(predicate)Collection:findKey()
#Performs find key on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:findKey(predicate) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
predicate |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:findKey(predicate)Collection:first()
#Performs first on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:first() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:first()Collection:firstKey()
#Performs first key on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:firstKey() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:firstKey()Collection:flatMap()
#Performs flat map on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:flatMap(fn) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
fn |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:flatMap(fn)Collection:forEach()
#Performs for each on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:forEach(fn) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
fn |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:forEach(fn)Collection:get()
#Performs get on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:get(key) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
key |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:get(key)Performs group by on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection.groupBy(iterable, keyFn) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
iterable |
any |
required | Passed through to the implementation as written. |
keyFn |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
Collection.groupBy(iterable, keyFn)Collection:has()
#Performs has on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:has(key) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
key |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:has(key)Collection:hasAll()
#Performs has all on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:hasAll(...) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
... |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:hasAll(...)Collection:hasAny()
#Performs has any on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:hasAny(...) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
... |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:hasAny(...)Collection:intersect()
#Predicate that returns whether this Collection matches intersect. Use it to branch before calling type-specific methods.
Signature
Collection:intersect(other) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
other |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:intersect(other)Collection:intersection()
#Predicate that returns whether this Collection matches intersection. Use it to branch before calling type-specific methods.
Signature
Collection:intersection(other) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
other |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:intersection(other)Collection:keyArray()
#Performs key array on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:keyArray() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:keyArray()Collection:keyAt()
#Performs key at on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:keyAt(index) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
index |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:keyAt(index)Collection:keys()
#Performs keys on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:keys() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:keys()Collection:last()
#Performs last on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:last() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:last()Collection:lastKey()
#Performs last key on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:lastKey() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:lastKey()Collection:map()
#Performs map on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:map(mapper) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
mapper |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:map(mapper)Collection:mapValues()
#Performs map values on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:mapValues(mapper) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
mapper |
any |
required | Passed through to the implementation as written. |
Returns
any.
Example
local discord = require("discord")
-- object is a Collection
object:mapValues(mapper)Collection:merge()
#Performs merge on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:merge(other, whenInSelf, whenInOther, whenInBoth) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
other |
any |
required | Passed through to the implementation as written. |
whenInSelf |
any |
required | Passed through to the implementation as written. |
whenInOther |
any |
required | Passed through to the implementation as written. |
whenInBoth |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:merge(other, whenInSelf, whenInOther, whenInBoth)Collection:partition()
#Performs partition on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:partition(predicate) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
predicate |
any |
required | Passed through to the implementation as written. |
Returns
any.
Example
local discord = require("discord")
-- object is a Collection
object:partition(predicate)Collection:random()
#Performs random on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:random() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:random()Collection:randomKey()
#Performs random key on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:randomKey() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:randomKey()Collection:reduce()
#Performs reduce on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:reduce(reducer, initial) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
reducer |
any |
required | Passed through to the implementation as written. |
initial |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:reduce(reducer, initial)Collection:reverse()
#Performs reverse on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:reverse() Parameters
No parameters.
Returns
any.
Example
local discord = require("discord")
-- object is a Collection
object:reverse()Collection:set()
#Performs set on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:set(key, value) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
key |
any |
required | Passed through to the implementation as written. |
value |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:set(key, value)Collection:size()
#Performs size on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:size() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:size()Collection:some()
#Performs some on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:some(predicate) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
predicate |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:some(predicate)Collection:sort()
#Performs sort on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:sort(compare) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
compare |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:sort(compare)Collection:subtract()
#Performs subtract on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:subtract(other) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
other |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:subtract(other)Collection:sweep()
#Performs sweep on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:sweep(predicate) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
predicate |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:sweep(predicate)Collection:tap()
#Performs tap on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:tap(fn) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
fn |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:tap(fn)Collection:toArray()
#Performs to array on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:toArray() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:toArray()Collection:toJSON()
#Serialize this Collection into a Lua table suitable for REST or debugging.
Signature
Collection:toJSON() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:toJSON()Collection:union()
#Performs union on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:union(other) Parameters
| Name | Type | Required | Behavior |
|---|---|---|---|
other |
any |
required | Passed through to the implementation as written. |
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:union(other)Collection:values()
#Performs values on this Collection. Call it from bot code when you need that operation on the current object.
Signature
Collection:values() Parameters
No parameters.
Returns
Collection — the same instance, for chaining.
Example
local discord = require("discord")
-- object is a Collection
object:values()Static members
-
Collection.LimitedCollection
Examples
local discord = require("discord")
local object = discord.Collection({})Related APIs
ActionRow · Activity · ActivityInstance · ActivityLocation · AnonymousGuild · ApplicationCommand · ApplicationRoleConnectionMetadata · Attachment
Version: discord 1.2.4 · runtime 1.0.0