Last change
on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
847 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 | // https://github.com/tc39/proposal-iterator-helpers
|
---|
| 3 | var $ = require('../internals/export');
|
---|
| 4 | var aFunction = require('../internals/a-function');
|
---|
| 5 | var anObject = require('../internals/an-object');
|
---|
| 6 | var createIteratorProxy = require('../internals/iterator-create-proxy');
|
---|
| 7 | var callWithSafeIterationClosing = require('../internals/call-with-safe-iteration-closing');
|
---|
| 8 |
|
---|
| 9 | var IteratorProxy = createIteratorProxy(function (arg) {
|
---|
| 10 | var iterator = this.iterator;
|
---|
| 11 | var result = anObject(this.next.call(iterator, arg));
|
---|
| 12 | var done = this.done = !!result.done;
|
---|
| 13 | if (!done) return callWithSafeIterationClosing(iterator, this.mapper, result.value);
|
---|
| 14 | });
|
---|
| 15 |
|
---|
| 16 | $({ target: 'Iterator', proto: true, real: true }, {
|
---|
| 17 | map: function map(mapper) {
|
---|
| 18 | return new IteratorProxy({
|
---|
| 19 | iterator: anObject(this),
|
---|
| 20 | mapper: aFunction(mapper)
|
---|
| 21 | });
|
---|
| 22 | }
|
---|
| 23 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.