Skip to content

Commit

Permalink
Minor doc and added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed May 30, 2017
1 parent d5da874 commit 476a83a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,7 +53,7 @@ function fibonacci() {
}
}
// Wrapper the Iterator result from calling the generator.
return genSequence(fib());
return genSequence(fib);
}

let fib5 = fibonacci()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 19 additions & 1 deletion src/GenSequence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,22 @@ describe('GenSequence Tests', function() {
const secondCount = filteredSequence.count();
expect(firstCount).to.equal(secondCount);
});
});

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];
}
}

0 comments on commit 476a83a

Please sign in to comment.