From 8e0ea9aa163983977c4cd8a1e1eca490612eb0cf Mon Sep 17 00:00:00 2001 From: 1Computer1 Date: Thu, 9 Aug 2018 08:25:07 -0400 Subject: [PATCH] Collection debug methods, remove deleteAll (#2577) --- src/util/Collection.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) 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