Skip to content

Commit

Permalink
Allow to shrink and expand a generator that hasn't generated any valu…
Browse files Browse the repository at this point in the history
…es yet
  • Loading branch information
sunesimonsen committed Nov 29, 2018
1 parent 00e7801 commit 1289922
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/GeneratorIterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,15 @@ class GeneratorIterator {
}

shrink() {
if (this.generated === uninitialized) {
throw new Error(
"You can't shrink an iterator that hasn't generated any values yet."
);
}

if (this.isShrinkable) {
if (this.generated !== uninitialized && this.isShrinkable) {
this.generator = this.generator.shrink(this.generated, this.context);
this.context = new Context();
this.isShrinkable = Boolean(this.generator.shrink);
}
}

expand() {
if (this.generated === uninitialized) {
throw new Error(
"You can't expand an iterator that hasn't generated any values yet."
);
}

if (this.isExpandable) {
if (this.generated !== uninitialized && this.isExpandable) {
this.generator = this.generator.expand(this.generated, this.context);
this.context = new Context();
this.isExpandable = Boolean(this.generator.expand);
Expand Down

0 comments on commit 1289922

Please sign in to comment.