massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / modules / esnext.iterator.reduce.js
1 'use strict';
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');
8
9 var TypeError = global.TypeError;
10
11 $({ target: 'Iterator', proto: true, real: true }, {
12   reduce: function reduce(reducer /* , initialValue */) {
13     anObject(this);
14     aCallable(reducer);
15     var noInitial = arguments.length < 2;
16     var accumulator = noInitial ? undefined : arguments[1];
17     iterate(this, function (value) {
18       if (noInitial) {
19         noInitial = false;
20         accumulator = value;
21       } else {
22         accumulator = reducer(accumulator, value);
23       }
24     }, { IS_ITERATOR: true });
25     if (noInitial) throw TypeError('Reduce of empty iterator with no initial value');
26     return accumulator;
27   }
28 });