added generator API to base iterators of Array, Map and Set...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-05-29 15:17:06 +03:00
parent 00ea1825cd
commit 71aba293c0
3 changed files with 25 additions and 2 deletions

View File

@ -1582,6 +1582,12 @@ terminology to reference different levels of API's:
In the above example `iter` is a generator instance.
Iterators and generators are similar but not the same. Some objects like `Array`'s,
`Map`'s and `Set`'s provide a number of generic iterators that are not implemented
as generators. These objects are also extended by `ig-types/generator` to match the
`<generator>` object API defined below.
#### `generator.Generator`

View File

@ -66,7 +66,17 @@ module.Generator =
(function*(){}).constructor
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// base iterator prototypes...
var ITERATOR_PROTOTYPES = [
Array,
Set,
Map,
].map(function(e){
return (new e()).values().__proto__ })
//---------------------------------------------------------------------
// generic generator wrapper...
var iter =
@ -395,6 +405,13 @@ GeneratorMixin(GeneratorPrototype)
GeneratorProtoMixin(GeneratorPrototype.prototype)
// Extend base iterators...
ITERATOR_PROTOTYPES
.forEach(function(proto){
GeneratorProtoMixin(proto) })
//---------------------------------------------------------------------
// Generators...

View File

@ -1,6 +1,6 @@
{
"name": "ig-types",
"version": "6.3.2",
"version": "6.4.0",
"description": "Generic JavaScript types and type extensions...",
"main": "main.js",
"scripts": {