1 | 'use strict';
|
2 | var $ = require('../internals/export');
|
3 | var call = require('../internals/function-call');
|
4 | var aCallable = require('../internals/a-callable');
|
5 | var anObject = require('../internals/an-object');
|
6 | var getIteratorDirect = require('../internals/get-iterator-direct');
|
7 | var createIteratorProxy = require('../internals/iterator-create-proxy');
|
8 | var callWithSafeIterationClosing = require('../internals/call-with-safe-iteration-closing');
|
9 | var IS_PURE = require('../internals/is-pure');
|
10 |
|
11 | var IteratorProxy = createIteratorProxy(function () {
|
12 | var iterator = this.iterator;
|
13 | var predicate = this.predicate;
|
14 | var next = this.next;
|
15 | var result, done, value;
|
16 | while (true) {
|
17 | result = anObject(call(next, iterator));
|
18 | done = this.done = !!result.done;
|
19 | if (done) return;
|
20 | value = result.value;
|
21 | if (callWithSafeIterationClosing(iterator, predicate, [value, this.counter++], true)) return value;
|
22 | }
|
23 | });
|
24 |
|
25 |
|
26 |
|
27 | $({ target: 'Iterator', proto: true, real: true, forced: IS_PURE }, {
|
28 | filter: function filter(predicate) {
|
29 | anObject(this);
|
30 | aCallable(predicate);
|
31 | return new IteratorProxy(getIteratorDirect(this), {
|
32 | predicate: predicate
|
33 | });
|
34 | }
|
35 | });
|