mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
feat(Collection): add tap method (#2507)
* Add Collection#inspect * No u * Rename to tap * Rename variable * Do it here too
This commit is contained in:
@@ -375,6 +375,24 @@ class Collection extends Map {
|
|||||||
return accumulator;
|
return accumulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identical to
|
||||||
|
* [Map.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach),
|
||||||
|
* but returns the collection instead of undefined.
|
||||||
|
* @param {Function} fn Function to execute for each element
|
||||||
|
* @param {*} [thisArg] Value to use as `this` when executing function
|
||||||
|
* @returns {Collection}
|
||||||
|
* @example
|
||||||
|
* collection
|
||||||
|
* .tap(user => console.log(user.username))
|
||||||
|
* .filter(user => user.bot)
|
||||||
|
* .tap(user => console.log(user.username));
|
||||||
|
*/
|
||||||
|
tap(fn, thisArg) {
|
||||||
|
this.forEach(fn, thisArg);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an identical shallow copy of this collection.
|
* Creates an identical shallow copy of this collection.
|
||||||
* @returns {Collection}
|
* @returns {Collection}
|
||||||
|
|||||||
Reference in New Issue
Block a user