From cb6e89d93b57f10cd4923598faaeef8cd8ebff5e Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Fri, 20 Sep 2024 09:04:34 -0300 Subject: [PATCH] fix: improving to-array After benchmarking different ways of implementing to-array, we chose to use for of + push, as it has shown the best performance for the cases this library is focused on --- lib/augmentative-iterable.js | 4 +--- package-lock.json | 2 +- package.json | 2 +- test/unit/iterable.spec.ts | 5 +++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/augmentative-iterable.js b/lib/augmentative-iterable.js index 1305e4b..a139a11 100644 --- a/lib/augmentative-iterable.js +++ b/lib/augmentative-iterable.js @@ -88,9 +88,7 @@ function augmentativeForEach( function augmentativeToArray() { const result = []; - - augmentativeForEach.call(this, result.push.bind(result)); - + for (const item of this) result.push(item); return result; } diff --git a/package-lock.json b/package-lock.json index 6df5dd4..8a7a647 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "augmentative-iterable", - "version": "1.6.0", + "version": "1.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0294b5d..711ffe2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "augmentative-iterable", "description": "This project is just a template for creation of new projects", - "version": "1.6.0", + "version": "1.6.1", "private": false, "author": { "name": "Thiago O Santos " diff --git a/test/unit/iterable.spec.ts b/test/unit/iterable.spec.ts index 74c4063..f68b1ad 100644 --- a/test/unit/iterable.spec.ts +++ b/test/unit/iterable.spec.ts @@ -10,6 +10,7 @@ import { addMapAsync, flatMapIterable, skipIterable, + augmentativeToArrayAsync, } from '../../index'; import { expect } from 'chai'; import { stub } from 'sinon'; @@ -254,7 +255,7 @@ describe('Iterable', () => { expect(result).to.be.eql([2, 3]); }); - it('should respect filter and takeWhile through operations', () => { + it('should respect filter and takeWhile through operations', async () => { const callFilter = stub().callsFake((x) => x !== 2); const callTakeWhile = stub().callsFake((x) => x < 4); const callMap = stub().callsFake((x) => x); @@ -263,7 +264,7 @@ describe('Iterable', () => { const takeWhile = addTakeWhile(filter, callTakeWhile); const map: any = addMapAsync(takeWhile, callMap); - const result = augmentativeToArray.call(map); + const result = await augmentativeToArrayAsync.call(map); expect(result).to.be.eql([1, 3]); expect(callFilter).to.have.callsLike([1], [2], [3], [4]);