Skip to content

Commit

Permalink
rename .asIndexedPairs to .indexed
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jul 24, 2022
1 parent e26a689 commit b21b574
Show file tree
Hide file tree
Showing 23 changed files with 199 additions and 55 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2180,17 +2180,17 @@ correctionNeeded; // => [1, 1, 3]
core-js(-pure)/stage/2
```
##### [Iterator helpers](https://github.com/tc39/proposal-iterator-helpers)[⬆](#index)
Modules [`esnext.async-iterator.constructor`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.constructor.js), [`esnext.async-iterator.as-indexed-pairs`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.as-indexed-pairs.js), [`esnext.async-iterator.drop`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.drop.js), [`esnext.async-iterator.every`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.every.js), [`esnext.async-iterator.filter`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.filter.js), [`esnext.async-iterator.find`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.find.js), [`esnext.async-iterator.flat-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.flat-map.js), [`esnext.async-iterator.for-each`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.for-each.js), [`esnext.async-iterator.from`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.from.js), [`esnext.async-iterator.map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.map.js), [`esnext.async-iterator.reduce`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.reduce.js), [`esnext.async-iterator.some`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.some.js), [`esnext.async-iterator.take`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.take.js), [`esnext.async-iterator.to-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.to-array.js), [`esnext.iterator.constructor`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.constructor.js), [`esnext.iterator.as-indexed-pairs`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.as-indexed-pairs.js), [`esnext.iterator.drop`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.drop.js), [`esnext.iterator.every`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.every.js), [`esnext.iterator.filter`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.filter.js), [`esnext.iterator.find`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.find.js), [`esnext.iterator.flat-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.flat-map.js), [`esnext.iterator.for-each`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.for-each.js), [`esnext.iterator.from`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.from.js), [`esnext.iterator.map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.map.js), [`esnext.iterator.reduce`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.reduce.js), [`esnext.iterator.some`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.some.js), [`esnext.iterator.take`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.take.js), [`esnext.iterator.to-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.to-array.js) and [`esnext.iterator.to-async`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.to-async.js)
Modules [`esnext.async-iterator.constructor`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.constructor.js), [`esnext.async-iterator.drop`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.drop.js), [`esnext.async-iterator.every`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.every.js), [`esnext.async-iterator.filter`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.filter.js), [`esnext.async-iterator.find`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.find.js), [`esnext.async-iterator.flat-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.flat-map.js), [`esnext.async-iterator.for-each`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.for-each.js), [`esnext.async-iterator.from`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.from.js), [`esnext.async-iterator.indexed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.indexed.js), [`esnext.async-iterator.map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.map.js), [`esnext.async-iterator.reduce`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.reduce.js), [`esnext.async-iterator.some`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.some.js), [`esnext.async-iterator.take`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.take.js), [`esnext.async-iterator.to-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.async-iterator.to-array.js), [`esnext.iterator.constructor`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.constructor.js), [`esnext.iterator.drop`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.drop.js), [`esnext.iterator.every`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.every.js), [`esnext.iterator.filter`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.filter.js), [`esnext.iterator.find`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.find.js), [`esnext.iterator.flat-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.flat-map.js), [`esnext.iterator.for-each`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.for-each.js), [`esnext.iterator.from`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.from.js), [`esnext.iterator.indexed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.indexed.js), [`esnext.iterator.map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.map.js), [`esnext.iterator.reduce`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.reduce.js), [`esnext.iterator.some`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.some.js), [`esnext.iterator.take`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.take.js), [`esnext.iterator.to-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.to-array.js) and [`esnext.iterator.to-async`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.iterator.to-async.js)
```js
class Iterator {
static from(iterable: Iterable<mixed>): Iterator<any>;
asIndexedPairs(): Iterator<[index, any]>;
drop(limit: uint): Iterator<any>;
every(callbackfn: value: any => boolean): boolean;
filter(callbackfn: value: any => boolean): Iterator<any>;
find(callbackfn: value: any => boolean)): any;
flatMap(callbackfn: value => any: Iterable): Iterator<any>;
forEach(callbackfn: value => void): void;
indexed(): Iterator<[index, any]>;
map(callbackfn: value => any): Iterator<any>;
reduce(callbackfn: (memo: any, value: any) => any, initialValue: any): any;
some(callbackfn: value: any => boolean): boolean;
Expand All @@ -2202,13 +2202,13 @@ class Iterator {
class AsyncIterator {
static from(iterable: Iterable<mixed>): AsyncIterator<any>;
asIndexedPairs(): AsyncIterator<[index, any]>;
drop(limit: uint): AsyncIterator<any>;
every(async callbackfn: value: any => boolean): Promise<boolean>;
filter(async callbackfn: value: any => boolean): AsyncIterator<any>;
find(async callbackfn: value: any => boolean)): Promise<any>;
flatMap(async callbackfn: value => any: Iterable): AsyncIterator<any>;
forEach(async callbackfn: value => void): Promise<void>;
indexed(): AsyncIterator<[index, any]>;
map(async callbackfn: value => any): AsyncIterator<any>;
reduce(async callbackfn: (memo: any, value: any) => any, initialValue: any): Promise<any>;
some(async callbackfn: value: any => boolean): Promise<boolean>;
Expand All @@ -2221,28 +2221,28 @@ class AsyncIterator {
```js
core-js/proposals/iterator-helpers
core-js(-pure)/full/async-iterator
core-js(-pure)/full/async-iterator/as-indexed-pairs
core-js(-pure)/full/async-iterator/drop
core-js(-pure)/full/async-iterator/every
core-js(-pure)/full/async-iterator/filter
core-js(-pure)/full/async-iterator/find
core-js(-pure)/full/async-iterator/flat-map
core-js(-pure)/full/async-iterator/for-each
core-js(-pure)/full/async-iterator/from
core-js(-pure)/full/async-iterator/indexed
core-js(-pure)/full/async-iterator/map
core-js(-pure)/full/async-iterator/reduce
core-js(-pure)/full/async-iterator/some
core-js(-pure)/full/async-iterator/take
core-js(-pure)/full/async-iterator/to-array
core-js(-pure)/full/iterator
core-js(-pure)/full/iterator/as-indexed-pairs
core-js(-pure)/full/iterator/drop
core-js(-pure)/full/iterator/every
core-js(-pure)/full/iterator/filter
core-js(-pure)/full/iterator/find
core-js(-pure)/full/iterator/flat-map
core-js(-pure)/full/iterator/for-each
core-js(-pure)/full/iterator/from
core-js(-pure)/full/iterator/indexed
core-js(-pure)/full/iterator/map
core-js(-pure)/full/iterator/reduce
core-js(-pure)/full/iterator/some
Expand Down
6 changes: 6 additions & 0 deletions packages/core-js-compat/src/data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,7 @@ export const data = {
},
'esnext.async-iterator.constructor': {
},
// TODO: Remove from `core-js@4`
'esnext.async-iterator.as-indexed-pairs': {
},
'esnext.async-iterator.drop': {
Expand All @@ -2096,6 +2097,8 @@ export const data = {
},
'esnext.async-iterator.from': {
},
'esnext.async-iterator.indexed': {
},
'esnext.async-iterator.map': {
},
'esnext.async-iterator.reduce': {
Expand All @@ -2122,6 +2125,7 @@ export const data = {
'esnext.global-this': null,
'esnext.iterator.constructor': {
},
// TODO: Remove from `core-js@4`
'esnext.iterator.as-indexed-pairs': {
},
'esnext.iterator.drop': {
Expand All @@ -2138,6 +2142,8 @@ export const data = {
},
'esnext.iterator.from': {
},
'esnext.iterator.indexed': {
},
'esnext.iterator.map': {
},
'esnext.iterator.reduce': {
Expand Down
4 changes: 4 additions & 0 deletions packages/core-js-compat/src/modules-by-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,8 @@ export default {
'esnext.array.group-to-map',
'esnext.symbol.metadata-key',
],
3.24: [
'esnext.async-iterator.indexed',
'esnext.iterator.indexed',
],
};
2 changes: 2 additions & 0 deletions packages/core-js/full/async-iterator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require('../../modules/es.object.to-string');
require('../../modules/es.promise');
require('../../modules/es.string.iterator');
require('../../modules/esnext.async-iterator.constructor');
// TODO: Remove from `core-js@4`
require('../../modules/esnext.async-iterator.as-indexed-pairs');
require('../../modules/esnext.async-iterator.drop');
require('../../modules/esnext.async-iterator.every');
Expand All @@ -11,6 +12,7 @@ require('../../modules/esnext.async-iterator.find');
require('../../modules/esnext.async-iterator.flat-map');
require('../../modules/esnext.async-iterator.for-each');
require('../../modules/esnext.async-iterator.from');
require('../../modules/esnext.async-iterator.indexed');
require('../../modules/esnext.async-iterator.map');
require('../../modules/esnext.async-iterator.reduce');
require('../../modules/esnext.async-iterator.some');
Expand Down
8 changes: 8 additions & 0 deletions packages/core-js/full/async-iterator/indexed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require('../../modules/es.object.to-string');
require('../../modules/es.promise');
require('../../modules/esnext.async-iterator.constructor');
require('../../modules/esnext.async-iterator.indexed');

var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('AsyncIterator', 'indexed');
2 changes: 2 additions & 0 deletions packages/core-js/full/iterator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require('../../modules/es.object.to-string');
require('../../modules/es.promise');
require('../../modules/es.string.iterator');
require('../../modules/esnext.iterator.constructor');
// TODO: Remove from `core-js@4`
require('../../modules/esnext.iterator.as-indexed-pairs');
require('../../modules/esnext.iterator.drop');
require('../../modules/esnext.iterator.every');
Expand All @@ -11,6 +12,7 @@ require('../../modules/esnext.iterator.find');
require('../../modules/esnext.iterator.flat-map');
require('../../modules/esnext.iterator.for-each');
require('../../modules/esnext.iterator.from');
require('../../modules/esnext.iterator.indexed');
require('../../modules/esnext.iterator.map');
require('../../modules/esnext.iterator.reduce');
require('../../modules/esnext.iterator.some');
Expand Down
8 changes: 8 additions & 0 deletions packages/core-js/full/iterator/indexed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require('../../modules/es.object.to-string');
require('../../modules/esnext.iterator.constructor');
require('../../modules/esnext.iterator.indexed');

var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Iterator', 'indexed');

25 changes: 25 additions & 0 deletions packages/core-js/internals/async-iterator-indexed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
// https://github.com/tc39/proposal-iterator-helpers
var apply = require('../internals/function-apply');
var anObject = require('../internals/an-object');
var getIteratorDirect = require('../internals/get-iterator-direct');
var createAsyncIteratorProxy = require('../internals/async-iterator-create-proxy');

var AsyncIteratorProxy = createAsyncIteratorProxy(function (Promise, args) {
var state = this;
var iterator = state.iterator;

return Promise.resolve(anObject(apply(state.next, iterator, args))).then(function (step) {
if (anObject(step).done) {
state.done = true;
return { done: true, value: undefined };
}
return { done: false, value: [state.index++, step.value] };
});
});

module.exports = function indexed() {
return new AsyncIteratorProxy(getIteratorDirect(this), {
index: 0
});
};
18 changes: 18 additions & 0 deletions packages/core-js/internals/iterator-indexed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
// https://github.com/tc39/proposal-iterator-helpers
var apply = require('../internals/function-apply');
var anObject = require('../internals/an-object');
var getIteratorDirect = require('../internals/get-iterator-direct');
var createIteratorProxy = require('../internals/iterator-create-proxy');

var IteratorProxy = createIteratorProxy(function (args) {
var result = anObject(apply(this.next, this.iterator, args));
var done = this.done = !!result.done;
if (!done) return [this.index++, result.value];
});

module.exports = function indexed() {
return new IteratorProxy(getIteratorDirect(this), {
index: 0
});
};
28 changes: 4 additions & 24 deletions packages/core-js/modules/esnext.async-iterator.as-indexed-pairs.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
'use strict';
// TODO: Remove from `core-js@4`
// https://github.com/tc39/proposal-iterator-helpers
var $ = require('../internals/export');
var apply = require('../internals/function-apply');
var anObject = require('../internals/an-object');
var getIteratorDirect = require('../internals/get-iterator-direct');
var createAsyncIteratorProxy = require('../internals/async-iterator-create-proxy');
var indexed = require('../internals/async-iterator-indexed');

var AsyncIteratorProxy = createAsyncIteratorProxy(function (Promise, args) {
var state = this;
var iterator = state.iterator;

return Promise.resolve(anObject(apply(state.next, iterator, args))).then(function (step) {
if (anObject(step).done) {
state.done = true;
return { done: true, value: undefined };
}
return { done: false, value: [state.index++, step.value] };
});
});

$({ target: 'AsyncIterator', proto: true, real: true, forced: true }, {
asIndexedPairs: function asIndexedPairs() {
return new AsyncIteratorProxy(getIteratorDirect(this), {
index: 0
});
}
$({ target: 'AsyncIterator', name: 'indexed', proto: true, real: true, forced: true }, {
asIndexedPairs: indexed
});
7 changes: 7 additions & 0 deletions packages/core-js/modules/esnext.async-iterator.indexed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// https://github.com/tc39/proposal-iterator-helpers
var $ = require('../internals/export');
var indexed = require('../internals/async-iterator-indexed');

$({ target: 'AsyncIterator', proto: true, real: true, forced: true }, {
indexed: indexed
});
21 changes: 4 additions & 17 deletions packages/core-js/modules/esnext.iterator.as-indexed-pairs.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
'use strict';
// TODO: Remove from `core-js@4`
// https://github.com/tc39/proposal-iterator-helpers
var $ = require('../internals/export');
var apply = require('../internals/function-apply');
var anObject = require('../internals/an-object');
var getIteratorDirect = require('../internals/get-iterator-direct');
var createIteratorProxy = require('../internals/iterator-create-proxy');
var indexed = require('../internals/iterator-indexed');

var IteratorProxy = createIteratorProxy(function (args) {
var result = anObject(apply(this.next, this.iterator, args));
var done = this.done = !!result.done;
if (!done) return [this.index++, result.value];
});

$({ target: 'Iterator', proto: true, real: true, forced: true }, {
asIndexedPairs: function asIndexedPairs() {
return new IteratorProxy(getIteratorDirect(this), {
index: 0
});
}
$({ target: 'Iterator', name: 'indexed', proto: true, real: true, forced: true }, {
asIndexedPairs: indexed
});
7 changes: 7 additions & 0 deletions packages/core-js/modules/esnext.iterator.indexed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// https://github.com/tc39/proposal-iterator-helpers
var $ = require('../internals/export');
var indexed = require('../internals/iterator-indexed');

$({ target: 'Iterator', proto: true, real: true, forced: true }, {
indexed: indexed
});
4 changes: 4 additions & 0 deletions packages/core-js/proposals/iterator-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// https://github.com/tc39/proposal-iterator-helpers
require('../modules/esnext.async-iterator.constructor');
// TODO: remove from `core-js@4`
require('../modules/esnext.async-iterator.as-indexed-pairs');
require('../modules/esnext.async-iterator.drop');
require('../modules/esnext.async-iterator.every');
Expand All @@ -8,12 +9,14 @@ require('../modules/esnext.async-iterator.find');
require('../modules/esnext.async-iterator.flat-map');
require('../modules/esnext.async-iterator.for-each');
require('../modules/esnext.async-iterator.from');
require('../modules/esnext.async-iterator.indexed');
require('../modules/esnext.async-iterator.map');
require('../modules/esnext.async-iterator.reduce');
require('../modules/esnext.async-iterator.some');
require('../modules/esnext.async-iterator.take');
require('../modules/esnext.async-iterator.to-array');
require('../modules/esnext.iterator.constructor');
// TODO: remove from `core-js@4`
require('../modules/esnext.iterator.as-indexed-pairs');
require('../modules/esnext.iterator.drop');
require('../modules/esnext.iterator.every');
Expand All @@ -22,6 +25,7 @@ require('../modules/esnext.iterator.find');
require('../modules/esnext.iterator.flat-map');
require('../modules/esnext.iterator.for-each');
require('../modules/esnext.iterator.from');
require('../modules/esnext.iterator.indexed');
require('../modules/esnext.iterator.map');
require('../modules/esnext.iterator.reduce');
require('../modules/esnext.iterator.some');
Expand Down
2 changes: 2 additions & 0 deletions scripts/check-compat-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const ignore = new Set([
'esnext.array.group-by-to-map',
'esnext.array.last-index',
'esnext.array.last-item',
'esnext.async-iterator.as-indexed-pairs',
'esnext.iterator.as-indexed-pairs',
'esnext.map.update-or-insert',
'esnext.map.upsert',
'esnext.math.iaddh',
Expand Down

0 comments on commit b21b574

Please sign in to comment.