@supercharge/collections
Advanced tools
Comparing version 1.8.0 to 1.9.0
# Changelog | ||
## [1.9.0](https://github.com/superchargejs/collections/compare/v1.8.0...v1.9.0) - 2019-10-26 | ||
### Added | ||
- `.pop()` method | ||
## [1.8.0](https://github.com/superchargejs/collections/compare/v1.7.0...v1.8.0) - 2019-10-24 | ||
@@ -5,0 +11,0 @@ |
{ | ||
"name": "@supercharge/collections", | ||
"description": "Supercharge collections", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"author": "Marcus Pöhls <marcus@futurestud.io>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -320,2 +320,17 @@ 'use strict' | ||
/** | ||
* Removes and returns the last item from the collection | ||
* | ||
* @param {} | ||
* | ||
* @returns {Number} | ||
*/ | ||
pop () { | ||
const collection = this.clone() | ||
this.splice(-1, 1) | ||
return collection._enqueue('pop').all() | ||
} | ||
/** | ||
* Asynchronous version of Array#reduce(). It invokes the `reducer` | ||
@@ -322,0 +337,0 @@ * function sequentially on each `array` item. The reducer |
@@ -345,2 +345,13 @@ 'use strict' | ||
/** | ||
* Removes and returns the last item from the collection | ||
* | ||
* @param {} | ||
* | ||
* @returns {Number} | ||
*/ | ||
pop () { | ||
return this.items.pop() | ||
} | ||
/** | ||
* Asynchronous version of Array#reduce(). It invokes the `reducer` | ||
@@ -347,0 +358,0 @@ * function sequentially on each `array` item. The reducer |
@@ -631,12 +631,28 @@ 'use strict' | ||
it('pop', async () => { | ||
expect( | ||
await Collect([1, 2, 3]).pop() | ||
).to.equal(3) | ||
const collection = Collect([]) | ||
const undef = await collection.pop() | ||
expect(undef).to.equal(undefined) | ||
expect(await collection.all()).to.equal([]) | ||
const pipeline = Collect([1, 2, 3, 4, 5]).map(item => item * 2).filter(item => item > 5) | ||
const ten = await pipeline.pop() | ||
expect(ten).to.equal(10) | ||
expect(await pipeline.all()).to.equal([6, 8]) | ||
}) | ||
it('shift', async () => { | ||
const collection = Collect([1, 2, 3]) | ||
const first = await collection.shift() | ||
expect(first).to.equal(1) | ||
const one = await collection.shift() | ||
expect(one).to.equal(1) | ||
expect(await collection.all()).to.equal([2, 3]) | ||
const pipeline = Collect([1, 2, 3]).map(item => item * 2).filter(item => item > 5) | ||
const pipeline = Collect([1, 2, 3, 4, 5]).map(item => item * 2).filter(item => item > 5) | ||
const six = await pipeline.shift() | ||
expect(six).to.equal(6) | ||
expect(await pipeline.all()).to.equal([]) | ||
expect(await pipeline.all()).to.equal([8, 10]) | ||
}) | ||
@@ -643,0 +659,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62794
1933