mirror of
https://github.com/flynx/types.js.git
synced 2025-12-19 09:51:40 +00:00
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:
parent
00ea1825cd
commit
71aba293c0
@ -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`
|
||||
|
||||
|
||||
19
generator.js
19
generator.js
@ -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...
|
||||
|
||||
|
||||
@ -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": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user