diff --git a/Promise.js b/Promise.js index 599c9d7..ef4ac4d 100644 --- a/Promise.js +++ b/Promise.js @@ -121,6 +121,14 @@ object.Constructor('IterablePromise', Promise, { return [] }) .then(function(){ return res }) }, + /* // XXX since order of execution is not fixed there is no point in + // adding this. + reduceRight: function(func, res){ + return this + .reverse() + .reduce(...arguments) + .reverse() }, + //*/ flat: function(depth=1){ return this.constructor(this, function(e){ @@ -156,6 +164,8 @@ object.Constructor('IterablePromise', Promise, { // .pop() // .shift() // .first() / .last() + // ...would be nice if these could stop everything that's not + // needed to execute... // XXX these can change the "resolved" state... // ...i.e. return a pending promise when called from a fulfilled // promise.... @@ -163,6 +173,36 @@ object.Constructor('IterablePromise', Promise, { // .push(..) // .unshift(..) // .first(..) / .last(..) + // XXX EXPEREMENTAL... + // ....can we remove a level of indirection here??? + // would be better to use the raw mode... + concat: function(other){ + var lst = this.__list + return lst instanceof Promise ? + this.constructor([this, other]) + .flat() + : other instanceof IterablePromise ? + this.constructor( + lst.concat(other.__list), + 'raw') + : other instanceof Promise ? + this.constructor( + lst.concat(other + .then(function(res){ + return res instanceof Array ? + res + : [res] })), + 'raw') + : this.constructor( + // XXX this is cheating -- need a more direct way to form the array... + lst.concat(this.constructor(other).__list), + 'raw') }, + push: function(elem){ + return this.concat([elem]) }, + // XXX this can be written in the same style as .concat(..) + unshift: function(elem){ + return this.constructor([elem]) + .concat(this) }, // Overload .then(..), .catch(..) and .finally(..) to return a plain diff --git a/README.md b/README.md index f1b22ca..8200ede 100644 --- a/README.md +++ b/README.md @@ -1613,7 +1613,10 @@ This is similar to [`.flat(..)`](https://developer.mozilla.org/en-US/docs -> ``` -This is similar to [`.reverse(..)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) see it for more info. +This is deferent from `.reverse()` in that it will _not_ reverse in-place, +but rather a _reversed copy_ will be created. + +This is similar to [`.reverse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) see it for more info. #### `.then(..)` / `.catch(..)` / `.finally(..)` diff --git a/package.json b/package.json index 1b2b67e..ac5ea5c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "6.11.3", + "version": "6.11.4", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": {