diff --git a/CHANGELOG.md b/CHANGELOG.md index d98cb56..3094d03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes +## 2.0.1 +* minor update to README.md. +* added test showing how it is not possible to reuse some iterators. + ## 2.0.0 * sequences are now reusable as long as the original iterator is reusable. * it is not possible to initialize a sequence with a function that returns an iterator diff --git a/README.md b/README.md index 04950af..6af0cc2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ are very exciting and provide some powerful new ways to solve programming proble The purpose of this library is to make using the results of a generator function easier. It is not intended as a replacement for arrays and the convenient [...genFn()] notation. GenSequence is useful for cases where you might not want an array of all possible values. -GenSequence deals effeciently with large sequences because only one element at a time is evaluated. +GenSequence deals efficiently with large sequences because only one element at a time is evaluated. Intermediate arrays are not created, saving memory and cpu cycles. ## Installation @@ -53,7 +53,7 @@ function fibonacci() { } } // Wrapper the Iterator result from calling the generator. - return genSequence(fib()); + return genSequence(fib); } let fib5 = fibonacci() diff --git a/package.json b/package.json index f1265ed..2b2e406 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gensequence", - "version": "2.0.0", + "version": "2.0.1", "description": "Small library to simplify working with Generators and Iterators in Javascript / Typescript", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/src/GenSequence.test.ts b/src/GenSequence.test.ts index 1d2c375..8caa4b3 100644 --- a/src/GenSequence.test.ts +++ b/src/GenSequence.test.ts @@ -523,4 +523,22 @@ describe('GenSequence Tests', function() { const secondCount = filteredSequence.count(); expect(firstCount).to.equal(secondCount); }); -}); \ No newline at end of file + + it('demonstrate that it is not possible to re-use iterators', () => { + const iter = fib(); + const seq = genSequence(iter); + const fib5 = seq.skip(5).first(); + const fib5b = seq.skip(5).first(); + expect(fib5).to.be.equal(8); + // Try reusing the iterator. + expect(fib5b).to.be.undefined; + }); +}); + +function* fib() { + let [a, b] = [0, 1]; + while (true) { + yield b; + [a, b] = [b, a + b]; + } +}