diff --git a/README.md b/README.md index 2626458..59494e7 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ Library of JavaScript type extensions, types and utilities. - [`.promise()`](#generatorpromise) - [`.then(..)` / `.catch(..)` / `.finally(..)`](#generatorthen--generatorcatch--generatorfinally) - [`.toArray()`](#generatortoarray) + - [Treating iterators the same as generators](#treating-iterators-the-same-as-generators) - [Generator constructor iteration](#generator-constructor-iteration) - [`.at(..)` / `.gat(..)`](#generatorat--generatorgat-1) - [`.shift()` / `.pop()` / `.gshift()` / `.gpop()`](#generatorshift--generatorpop--generatorgshift--generatorgpop-1) @@ -1807,6 +1808,23 @@ Unwind a generator into an array This is equivalent to `[...]` but more suited for the concatenative style. +### Treating iterators the same as generators + +Most _iterator_ methods of `Array`, `Set` and `Map` are extended with the same +API supported by the [``](#generator-instance-iteration), so +effectively most built-in iterator methods can be transparently treated as +generators. + +```javascript +// this will generate: [1, 4, 9] +var L = [ ...[1, 2, 3] + // Note that this is implemented as an iterator in JS and not a generator... + .values() + .map(function(e){ + return e * e }) ] +``` + + ### Generator constructor iteration This API is essentially the same as [generator iteration](#generator-instance-iteration)