ig-types 6.11.3 → 6.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Promise.js +43 -8
- package/README.md +58 -17
- package/package.json +1 -1
package/Promise.js
CHANGED
|
@@ -121,6 +121,14 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
121
121
|
return [] })
|
|
122
122
|
.then(function(){
|
|
123
123
|
return res }) },
|
|
124
|
+
/* // XXX since order of execution is not fixed there is no point in
|
|
125
|
+
// adding this.
|
|
126
|
+
reduceRight: function(func, res){
|
|
127
|
+
return this
|
|
128
|
+
.reverse()
|
|
129
|
+
.reduce(...arguments)
|
|
130
|
+
.reverse() },
|
|
131
|
+
//*/
|
|
124
132
|
flat: function(depth=1){
|
|
125
133
|
return this.constructor(this,
|
|
126
134
|
function(e){
|
|
@@ -152,18 +160,45 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
152
160
|
.reverse(),
|
|
153
161
|
'raw') },
|
|
154
162
|
|
|
163
|
+
// NOTE: these can create an unresolved promise from a resolved
|
|
164
|
+
// promise...
|
|
165
|
+
// XXX EXPEREMENTAL...
|
|
166
|
+
// ....can we remove a level of indirection here???
|
|
167
|
+
// would be better to use the raw mode...
|
|
168
|
+
concat: function(other){
|
|
169
|
+
var lst = this.__list
|
|
170
|
+
return lst instanceof Promise ?
|
|
171
|
+
this.constructor([this, other])
|
|
172
|
+
.flat()
|
|
173
|
+
: other instanceof IterablePromise ?
|
|
174
|
+
this.constructor(
|
|
175
|
+
lst.concat(other.__list),
|
|
176
|
+
'raw')
|
|
177
|
+
: other instanceof Promise ?
|
|
178
|
+
this.constructor(
|
|
179
|
+
lst.concat(other
|
|
180
|
+
.then(function(res){
|
|
181
|
+
return res instanceof Array ?
|
|
182
|
+
res
|
|
183
|
+
: [res] })),
|
|
184
|
+
'raw')
|
|
185
|
+
: this.constructor(
|
|
186
|
+
// XXX this is cheating -- need a more direct way to form the array...
|
|
187
|
+
lst.concat(this.constructor(other).__list),
|
|
188
|
+
'raw') },
|
|
189
|
+
push: function(elem){
|
|
190
|
+
return this.concat([elem]) },
|
|
191
|
+
unshift: function(elem){
|
|
192
|
+
return this.constructor([elem])
|
|
193
|
+
.concat(this) },
|
|
194
|
+
|
|
155
195
|
// XXX do we need these?
|
|
156
196
|
// .pop()
|
|
157
197
|
// .shift()
|
|
158
198
|
// .first() / .last()
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
// .concat(..)
|
|
163
|
-
// .push(..)
|
|
164
|
-
// .unshift(..)
|
|
165
|
-
// .first(..) / .last(..)
|
|
166
|
-
|
|
199
|
+
// ...would be nice if these could stop everything that's not
|
|
200
|
+
// needed to execute...
|
|
201
|
+
|
|
167
202
|
|
|
168
203
|
// Overload .then(..), .catch(..) and .finally(..) to return a plain
|
|
169
204
|
// Promise instnace...
|
package/README.md
CHANGED
|
@@ -75,6 +75,8 @@ Library of JavaScript type extensions, types and utilities.
|
|
|
75
75
|
- [`<promise-iter>.map(..)` / `<promise-iter>.filter(..)` / `<promise-iter>.reduce(..)`](#promise-itermap--promise-iterfilter--promise-iterreduce)
|
|
76
76
|
- [`<promise-iter>.flat(..)`](#promise-iterflat)
|
|
77
77
|
- [`<promise-iter>.reverse()`](#promise-iterreverse)
|
|
78
|
+
- [`<promise-iter>.concat(..)`](#promise-iterconcat)
|
|
79
|
+
- [`<promise-iter>.push(..)` / `<promise-iter>.unshift(..)`](#promise-iterpush--promise-iterunshift)
|
|
78
80
|
- [`<promise-iter>.then(..)` / `<promise-iter>.catch(..)` / `<promise-iter>.finally(..)`](#promise-iterthen--promise-itercatch--promise-iterfinally)
|
|
79
81
|
- [Advanced handler](#advanced-handler)
|
|
80
82
|
- [Promise proxies](#promise-proxies)
|
|
@@ -1613,7 +1615,35 @@ This is similar to [`<array>.flat(..)`](https://developer.mozilla.org/en-US/docs
|
|
|
1613
1615
|
-> <promise-iter>
|
|
1614
1616
|
```
|
|
1615
1617
|
|
|
1616
|
-
This is
|
|
1618
|
+
This is deferent from `<array>.reverse()` in that it will _not_ reverse in-place,
|
|
1619
|
+
but rather a _reversed copy_ will be created.
|
|
1620
|
+
|
|
1621
|
+
This is similar to [`<array>.reverse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) see it for more info.
|
|
1622
|
+
|
|
1623
|
+
|
|
1624
|
+
#### `<promise-iter>.concat(..)`
|
|
1625
|
+
|
|
1626
|
+
```bnf
|
|
1627
|
+
<promise-iter>.concat(<other>)
|
|
1628
|
+
-> <promise-iter>
|
|
1629
|
+
```
|
|
1630
|
+
|
|
1631
|
+
This is similar to [`<array>.concat(..)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) see it for more info.
|
|
1632
|
+
|
|
1633
|
+
|
|
1634
|
+
#### `<promise-iter>.push(..)` / `<promise-iter>.unshift(..)`
|
|
1635
|
+
|
|
1636
|
+
```bnf
|
|
1637
|
+
<promise-iter>.push(<elem>)
|
|
1638
|
+
-> <promise-iter>
|
|
1639
|
+
|
|
1640
|
+
<promise-iter>.unshift(<elem>)
|
|
1641
|
+
-> <promise-iter>
|
|
1642
|
+
```
|
|
1643
|
+
|
|
1644
|
+
These are similar to [`<array>.push(..)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
|
|
1645
|
+
and [`<array>.unshift(..)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
|
|
1646
|
+
see them for more info.
|
|
1617
1647
|
|
|
1618
1648
|
|
|
1619
1649
|
#### `<promise-iter>.then(..)` / `<promise-iter>.catch(..)` / `<promise-iter>.finally(..)`
|
|
@@ -1633,40 +1663,51 @@ can be useful to hide the extended promise API from further code.
|
|
|
1633
1663
|
#### Advanced handler
|
|
1634
1664
|
|
|
1635
1665
|
```bnf
|
|
1636
|
-
Promise.iter(<block
|
|
1666
|
+
Promise.iter(<block>, <handler>)
|
|
1637
1667
|
-> <iterable-promise>
|
|
1668
|
+
```
|
|
1638
1669
|
|
|
1639
|
-
|
|
1640
|
-
|
|
1670
|
+
The `<handler>` will get passed each resolved `<value>` of the input `<block>`
|
|
1671
|
+
as soon as it's available/resolved.
|
|
1672
|
+
|
|
1673
|
+
The `<handler>` return value is unwrapped into the resulting array, allowing
|
|
1674
|
+
each call to both remove elements (i.e. returning `[]`) from the resulting
|
|
1675
|
+
`<block>` as well as insert multiple items (by returning an array of items).
|
|
1676
|
+
|
|
1677
|
+
<!-- XXX returning promises from handler needs to be documented/tested... -->
|
|
1678
|
+
|
|
1679
|
+
```bnf
|
|
1680
|
+
<handler>(<value>)
|
|
1681
|
+
-> []
|
|
1682
|
+
-> [ <elem>, .. ]
|
|
1683
|
+
-> <non-array>
|
|
1641
1684
|
```
|
|
1642
1685
|
|
|
1643
1686
|
```bnf
|
|
1644
|
-
<block
|
|
1687
|
+
<block> ::=
|
|
1645
1688
|
[]
|
|
1646
|
-
| [ <
|
|
1689
|
+
| [ <elem>, .. ]
|
|
1647
1690
|
|
|
1648
|
-
<
|
|
1649
|
-
|
|
1650
|
-
|
|
|
1651
|
-
| <promise>
|
|
1652
|
-
| <non-array>
|
|
1691
|
+
<elem> ::=
|
|
1692
|
+
<value>
|
|
1693
|
+
| <promise>(<value>)
|
|
1653
1694
|
```
|
|
1654
1695
|
|
|
1655
1696
|
Example:
|
|
1656
1697
|
```javascript
|
|
1657
1698
|
var p = Promise.iter(
|
|
1658
|
-
|
|
1659
|
-
// an array -- like the last element here...
|
|
1660
|
-
[[1, 2], 3, Promise.resolve(4), [[5, 6]]],
|
|
1699
|
+
[1, 2, 3, Promise.resolve(4), [5, 6]],
|
|
1661
1700
|
function(elem){
|
|
1701
|
+
// duplicate even numbers...
|
|
1662
1702
|
return elem % 2 == 0 ?
|
|
1663
1703
|
[elem, elem]
|
|
1704
|
+
// return arrays as-is...
|
|
1664
1705
|
: elem instanceof Array ?
|
|
1665
|
-
|
|
1706
|
+
[elem]
|
|
1707
|
+
// remove other elements...
|
|
1666
1708
|
: [] })
|
|
1667
1709
|
.then(function(lst){
|
|
1668
|
-
console.log(lst) // -> [2, 2, 4, 4, [5, 6]]
|
|
1669
|
-
})
|
|
1710
|
+
console.log(lst) }) // -> [2, 2, 4, 4, [5, 6]]
|
|
1670
1711
|
```
|
|
1671
1712
|
|
|
1672
1713
|
|