Skip to content

Commit

Permalink
refactor(done): don't use done() method
Browse files Browse the repository at this point in the history
  • Loading branch information
blond committed Aug 11, 2016
1 parent 68abd9d commit d200239
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 26 deletions.
8 changes: 0 additions & 8 deletions lib/done.js

This file was deleted.

3 changes: 1 addition & 2 deletions lib/evenly.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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 @@ -78,7 +77,7 @@ function evenly(iterables) {
function next() {
// Exit if all iterators are traversed.
if (empties.size === count) {
return done();
return { done: true };
}

// Go to the next iterator.
Expand Down
4 changes: 1 addition & 3 deletions lib/object-entries-iterator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'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 @@ -42,7 +40,7 @@ module.exports = class ObjectEntriesIterator {
}
next() {
if (this._index === this._length) {
return done();
return { done: true };
}

const key = this._keys[this._index++];
Expand Down
3 changes: 1 addition & 2 deletions lib/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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 @@ -50,7 +49,7 @@ function series(iterables) {
while (next.done) {
// If iterators are ended, then exit.
if (iterables.length === 0) {
return done();
return { done: true };
}

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

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

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

this._done = true;
Expand Down
5 changes: 2 additions & 3 deletions test/evenly/iterator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ const test = require('ava');

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

test('should return empty iterator', t => {
const iter = evenly();

t.deepEqual(iter.next(), done());
t.deepEqual(iter.next(), { done: true });
});

test('should support empty iterator', t => {
const emptyIter = createIterator();

const iter = evenly(emptyIter);

t.deepEqual(iter.next(), done());
t.deepEqual(iter.next(), { done: true });
});

test('should return equal iterator', t => {
Expand Down
3 changes: 1 addition & 2 deletions test/is-iterator/iterable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
const test = require('ava');

const isIterator = require('../../lib/is-iterator');
const done = require('../../lib/done');

test('iterable object should not be iterator', t => {
const iterable = {
[Symbol.iterator]() {
return {
next: () => (done)
next: () => ({ done: true })
};
}
};
Expand Down
5 changes: 2 additions & 3 deletions test/series/iterator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ const test = require('ava');

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

test('should return empty iterator', t => {
const iter = series();

t.deepEqual(iter.next(), done());
t.deepEqual(iter.next(), { done: true });
});

test('should support empty iterator', t => {
const emptyIter = createIterator();

const iter = series(emptyIter);

t.deepEqual(iter.next(), done());
t.deepEqual(iter.next(), { done: true });
});

test('should return equal iterator', t => {
Expand Down

0 comments on commit d200239

Please sign in to comment.