main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
945 bytes
|
Line | |
---|
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 | // `Iterator.prototype.map` method
|
---|
17 | // https://github.com/tc39/proposal-iterator-helpers
|
---|
18 | module.exports = function map(mapper) {
|
---|
19 | anObject(this);
|
---|
20 | aCallable(mapper);
|
---|
21 | return new IteratorProxy(getIteratorDirect(this), {
|
---|
22 | mapper: mapper
|
---|
23 | });
|
---|
24 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.