From 56409eed094173a217a3815a07f68436e8209ff8 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 3 May 2021 02:56:23 +0300 Subject: [PATCH] docs... Signed-off-by: Alex A. Naanou --- README.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 69a7b3e..648c02f 100644 --- a/README.md +++ b/README.md @@ -1530,9 +1530,6 @@ var p = Promise.iter( var generator = require('ig-types/generator') ``` - - - ### The basics @@ -1554,10 +1551,13 @@ We can test that `iter` is an instance of `Iter`: iter instanceof Iter // -> true ``` +Note that there is no generator constructor constructor or _meta-generator_, +i.e. `Iter` is created syntactically and not constructed via a `new` _constructor_. + Due to the three level structure of generators we use a slightly different terminology to reference different levels of API's: - `Generator` - the generator meta-constructor. - This is a constructor that is used to create/inherit ``'s, i.e. + This is a constructor that is used to create/prototype ``'s, i.e. generator constructors. `Generator` is mainly used for `instanceof` checks, but can be used as a prototype for extending generators. @@ -1576,12 +1576,25 @@ terminology to reference different levels of API's: Exposes the _hidden_ JavaScript generator meta-constructor. +This is similar to the JavaScript's +[`Function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) constructor +```javascript +var g = generator.Generator(` + yield 123 + yield 321 `) + +// prints 123 then 321... +for(var e of g()){ + console.log(e.value) } +``` + +This can be used to test if a function is a _generator constructor_ ```javascript Iter instanceof generator.Generator // -> true ``` -Note that currently in JavaScript there is no built-in way to test if a -constructor, `Iter` in this case, is a _generator_ constructor. +Note that currently in JavaScript there is no _built-in_ way to test if a +constructor/function, `Iter` in this case, is a _generator_ constructor. #### `generator.iter(..)`