diff --git a/src/util/Collection.js b/src/util/Collection.js index 06f54f59c..86b4e5aa9 100644 --- a/src/util/Collection.js +++ b/src/util/Collection.js @@ -333,12 +333,29 @@ class Collection extends Map { * @returns {Collection} * @example * collection - * .tap(user => console.log(user.username)) + * .each(user => console.log(user.username)) * .filter(user => user.bot) - * .tap(user => console.log(user.username)); + * .each(user => console.log(user.username)); + */ + each(fn, thisArg) { + this.forEach(fn, thisArg); + return this; + } + + /** + * Runs a function on the collection and returns the collection. + * @param {Function} fn Function to execute + * @param {*} [thisArg] Value to use as `this` when executing function + * @returns {Collection} + * @example + * collection + * .tap(coll => coll.size) + * .filter(user => user.bot) + * .tap(coll => coll.size) */ tap(fn, thisArg) { - this.forEach(fn, thisArg); + if (typeof thisArg !== 'undefined') fn = fn.bind(thisArg); + fn(this); return this; } @@ -365,18 +382,6 @@ class Collection extends Map { return newColl; } - /** - * Calls the `delete()` method on all items that have it. - * @returns {Promise[]} - */ - deleteAll() { - const returns = []; - for (const item of this.values()) { - if (item.delete) returns.push(item.delete()); - } - return returns; - } - /** * Checks if this collection shares identical key-value pairings with another. * This is different to checking for equality using equal-signs, because