Add Collection.concat

This commit is contained in:
Schuyler Cebulskie
2016-09-27 20:47:12 -04:00
parent aed75e1f9a
commit 0bcca7bb55
2 changed files with 16 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -248,6 +248,21 @@ class Collection extends Map {
return currentVal;
}
/**
* Combines this collection with others into a new collection. None of the source collections are modified.
* @param {Collection} collections Collections to merge
* @returns {Collection}
* @example const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
*/
concat(...collections) {
const newColl = new this.constructor();
for (const [key, val] of this) newColl.set(key, val);
for (const coll of collections) {
for (const [key, val] of coll) newColl.set(key, val);
}
return newColl;
}
/**
* If the items in this collection have a delete method (e.g. messages), invoke
* the delete method. Returns an array of promises