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:
1Computer1
2018-05-04 03:08:32 -04:00
committed by SpaceEEC
parent 2b6592ed54
commit de7d90ada3

View File

@@ -375,6 +375,24 @@ class Collection extends Map {
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.
* @returns {Collection}