diff --git a/README.md b/README.md index 9b11c1b..79f3413 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ Library of JavaScript type extensions, types and utilities. - [`.iter(..)`](#generatoriter-1) - [`.map(..)` / `.filter(..)`](#generatormap--generatorfilter) - [`.reduce(..)` / `.greduce(..)`](#generatorreduce--generatorgreduce) + - [`.forEach(..)`](#generatorforeach) - [`.slice(..)`](#generatorslice) - [`.at(..)` / `.gat(..)`](#generatorat--generatorgat) - [`.flat(..)`](#generatorflat) @@ -2135,6 +2136,17 @@ XXX .reduce(..) can return a non-iterable -- test and document this case... ...compare with Array.prototype.reduce(..) --> +#### `.forEach(..)` + +```bnf +.forEach() + -> +``` + +This is different from the above in that this will unwind the ``. + +Note that this differs from `.forEach(..)` in that his will return the resulting array, essentially behaving like `.map(..)`. + #### `.slice(..)` diff --git a/generator.js b/generator.js index 4cb7713..d9593ca 100644 --- a/generator.js +++ b/generator.js @@ -223,6 +223,12 @@ object.Mixin('GeneratorMixin', 'soft', { reduce: makeGenerator('reduce'), reduceRight: makeGenerator('reduceRight'), + // XXX add .toString(..) ??? + forEach: function(func){ + var that = this + return function(){ + return that(...arguments).forEach(func) } }, + // non-generators... // toArray: function(){ @@ -397,6 +403,12 @@ object.Mixin('GeneratorProtoMixin', 'soft', { greduce: function*(func, res){ yield this.reduce(...arguments) }, + // NOTE: this is a special case in that it will unwind the generator... + // NOTE: this is different from .forEach(..) in that this will + // return the resulting array. + forEach: function(func){ + return [...this].map(func) }, + pop: function(){ return [...this].pop() }, // XXX this needs the value to be iterable... diff --git a/package.json b/package.json index cf33f49..2df51fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "6.16.3", + "version": "6.16.4", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": {