]> git.r.bdr.sh - rbdr/dotfiles/blob
6dc1543b35453149347e6512d461601a5d366100
[rbdr/dotfiles] /
1 'use strict';
2
3 var setPrototypeOf = require('es5-ext/object/set-prototype-of')
4 , d = require('d')
5 , Iterator = require('../')
6 , validIterable = require('../valid-iterable')
7
8 , push = Array.prototype.push
9 , defineProperties = Object.defineProperties
10 , IteratorChain;
11
12 IteratorChain = function (iterators) {
13 defineProperties(this, {
14 __iterators__: d('', iterators),
15 __current__: d('w', iterators.shift())
16 });
17 };
18 if (setPrototypeOf) setPrototypeOf(IteratorChain, Iterator);
19
20 IteratorChain.prototype = Object.create(Iterator.prototype, {
21 constructor: d(IteratorChain),
22 next: d(function () {
23 var result;
24 if (!this.__current__) return { done: true, value: undefined };
25 result = this.__current__.next();
26 while (result.done) {
27 this.__current__ = this.__iterators__.shift();
28 if (!this.__current__) return { done: true, value: undefined };
29 result = this.__current__.next();
30 }
31 return result;
32 })
33 });
34
35 module.exports = function () {
36 var iterators = [this];
37 push.apply(iterators, arguments);
38 iterators.forEach(validIterable);
39 return new IteratorChain(iterators);
40 };