2 // https://github.com/tc39/proposal-iterator-helpers
3 var $ = require('../internals/export');
4 var global = require('../internals/global');
5 var iterate = require('../internals/iterate');
6 var aCallable = require('../internals/a-callable');
7 var anObject = require('../internals/an-object');
9 var TypeError = global.TypeError;
11 $({ target: 'Iterator', proto: true, real: true }, {
12 reduce: function reduce(reducer /* , initialValue */) {
15 var noInitial = arguments.length < 2;
16 var accumulator = noInitial ? undefined : arguments[1];
17 iterate(this, function (value) {
22 accumulator = reducer(accumulator, value);
24 }, { IS_ITERATOR: true });
25 if (noInitial) throw TypeError('Reduce of empty iterator with no initial value');