Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
878 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | // https://github.com/tc39/proposal-iterator-helpers
|
---|
3 | var $ = require('../internals/export');
|
---|
4 | var anObject = require('../internals/an-object');
|
---|
5 | var toPositiveInteger = require('../internals/to-positive-integer');
|
---|
6 | var createIteratorProxy = require('../internals/iterator-create-proxy');
|
---|
7 | var iteratorClose = require('../internals/iterator-close');
|
---|
8 |
|
---|
9 | var IteratorProxy = createIteratorProxy(function (arg) {
|
---|
10 | var iterator = this.iterator;
|
---|
11 | if (!this.remaining--) {
|
---|
12 | this.done = true;
|
---|
13 | return iteratorClose(iterator);
|
---|
14 | }
|
---|
15 | var result = anObject(this.next.call(iterator, arg));
|
---|
16 | var done = this.done = !!result.done;
|
---|
17 | if (!done) return result.value;
|
---|
18 | });
|
---|
19 |
|
---|
20 | $({ target: 'Iterator', proto: true, real: true }, {
|
---|
21 | take: function take(limit) {
|
---|
22 | return new IteratorProxy({
|
---|
23 | iterator: anObject(this),
|
---|
24 | remaining: toPositiveInteger(limit)
|
---|
25 | });
|
---|
26 | }
|
---|
27 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.