1 | 'use strict';
|
2 | var call = require('../internals/function-call');
|
3 | var aCallable = require('../internals/a-callable');
|
4 | var anObject = require('../internals/an-object');
|
5 | var getIteratorDirect = require('../internals/get-iterator-direct');
|
6 | var createIteratorProxy = require('../internals/iterator-create-proxy');
|
7 | var callWithSafeIterationClosing = require('../internals/call-with-safe-iteration-closing');
|
8 |
|
9 | var IteratorProxy = createIteratorProxy(function () {
|
10 | var iterator = this.iterator;
|
11 | var result = anObject(call(this.next, iterator));
|
12 | var done = this.done = !!result.done;
|
13 | if (!done) return callWithSafeIterationClosing(iterator, this.mapper, [result.value, this.counter++], true);
|
14 | });
|
15 |
|
16 |
|
17 |
|
18 | module.exports = function map(mapper) {
|
19 | anObject(this);
|
20 | aCallable(mapper);
|
21 | return new IteratorProxy(getIteratorDirect(this), {
|
22 | mapper: mapper
|
23 | });
|
24 | };
|