mirror of
https://github.com/flynx/types.js.git
synced 2025-12-19 18:01:39 +00:00
added .froEach(..) to sync generators...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
72909c35b2
commit
934e3dd216
12
README.md
12
README.md
@ -100,6 +100,7 @@ Library of JavaScript type extensions, types and utilities.
|
||||
- [`<generator>.iter(..)`](#generatoriter-1)
|
||||
- [`<generator>.map(..)` / `<generator>.filter(..)`](#generatormap--generatorfilter)
|
||||
- [`<generator>.reduce(..)` / `<generator>.greduce(..)`](#generatorreduce--generatorgreduce)
|
||||
- [`<generator>.forEach(..)`](#generatorforeach)
|
||||
- [`<generator>.slice(..)`](#generatorslice)
|
||||
- [`<generator>.at(..)` / `<generator>.gat(..)`](#generatorat--generatorgat)
|
||||
- [`<generator>.flat(..)`](#generatorflat)
|
||||
@ -2135,6 +2136,17 @@ XXX .reduce(..) can return a non-iterable -- test and document this case...
|
||||
...compare with Array.prototype.reduce(..)
|
||||
-->
|
||||
|
||||
#### `<generator>.forEach(..)`
|
||||
|
||||
```bnf
|
||||
<generator>.forEach(<func>)
|
||||
-> <array>
|
||||
```
|
||||
|
||||
This is different from the above in that this will unwind the `<generator>`.
|
||||
|
||||
Note that this differs from `<array>.forEach(..)` in that his will return the resulting array, essentially behaving like `.map(..)`.
|
||||
|
||||
|
||||
#### `<generator>.slice(..)`
|
||||
|
||||
|
||||
12
generator.js
12
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 <array>.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...
|
||||
|
||||
@ -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": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user