Skip to content

Commit

Permalink
refactor(done): add freezed done object
Browse files Browse the repository at this point in the history
  • Loading branch information
blond committed Aug 12, 2016
1 parent d200239 commit 82304fe
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/done.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = Object.freeze({ done: true });
3 changes: 2 additions & 1 deletion lib/evenly.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const unspread = require('spread-args').unspread;

const createIterator = require('./create-iterator');
const done = require('./done');

/**
* Returns an Iterator, that traverses iterators evenly.
Expand Down Expand Up @@ -77,7 +78,7 @@ function evenly(iterables) {
function next() {
// Exit if all iterators are traversed.
if (empties.size === count) {
return { done: true };
return done;
}

// Go to the next iterator.
Expand Down
4 changes: 3 additions & 1 deletion lib/object-entries-iterator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const done = require('./done');

/**
* Creates an iterator whose elements are arrays corresponding to the enumerable property [key, value] pairs
* found directly upon object.
Expand Down Expand Up @@ -40,7 +42,7 @@ module.exports = class ObjectEntriesIterator {
}
next() {
if (this._index === this._length) {
return { done: true };
return done;
}

const key = this._keys[this._index++];
Expand Down
3 changes: 2 additions & 1 deletion lib/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const unspread = require('spread-args').unspread;

const createIterator = require('./create-iterator');
const done = require('./done');

/**
* Returns an Iterator, that traverses iterators in series.
Expand Down Expand Up @@ -49,7 +50,7 @@ function series(iterables) {
while (next.done) {
// If iterators are ended, then exit.
if (iterables.length === 0) {
return { done: true };
return done;
}

iter = createIterator(iterables.shift(), { strict: false });
Expand Down
4 changes: 3 additions & 1 deletion lib/value-iterator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const done = require('./done');

/**
* Iterator with specified value.
*
Expand All @@ -22,7 +24,7 @@ module.exports = class ValueIterator {
}
next() {
if (this._done) {
return { done: true };
return done;
}

this._done = true;
Expand Down

0 comments on commit 82304fe

Please sign in to comment.