ig-types 6.11.0 → 6.11.1

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/Array.js CHANGED
@@ -492,6 +492,7 @@ object.Mixin('ArrayProtoMixin', 'soft', {
492
492
  smap: stoppableList('map'),
493
493
  sfilter: stoppableList('filter'),
494
494
  sreduce: stoppableValue('reduce'),
495
+ sreduceRight: stoppableValue('reduceRight'),
495
496
  sforEach: stoppableValue('map', true),
496
497
 
497
498
  // Chunk iteration...
package/Promise.js CHANGED
@@ -80,12 +80,13 @@ object.Constructor('IterablePromise', Promise, {
80
80
  // NOTE: these are different to Array's equivalents in that the handler
81
81
  // is called not in the order of the elements but rather in order
82
82
  // of promise resolution...
83
- // NOTE: index of items is unknowable because items can expand on
83
+ // NOTE: index of items is unknowable because items can expand and
84
84
  // contract depending on handlrs (e.g. .filter(..) can remove
85
85
  // items)...
86
86
  // This the following can not be implemented here:
87
87
  // .slice(..)
88
88
  // .splice(..)
89
+ // .values() / .keys()
89
90
  // .at(..)
90
91
  // [Symbol.iterator]() - needs to be sync...
91
92
  // The followng methods are questionable:
@@ -93,36 +94,61 @@ object.Constructor('IterablePromise', Promise, {
93
94
  // .includes(..)
94
95
  // .some(..) / .every(..)
95
96
  // .sort(..)
97
+ // XXX BUG:
98
+ // Promise.iter([1,2,3])
99
+ // .map(e => e)
100
+ // is not the same as:
101
+ // Promise.iter([1,2,3])
102
+ // .map(e => e)
103
+ // .map(e => e)
96
104
  // XXX should these support STOP???
97
105
  map: function(func){
98
- return this.constructor(this.__list,
106
+ return this.constructor(this.__list.flat(),
99
107
  function(e){
100
108
  return [func(e)] }) },
101
109
  filter: function(func){
102
- return this.constructor(this.__list,
110
+ return this.constructor(this.__list.flat(),
103
111
  function(e){
104
112
  return func(e) ?
105
113
  [e]
106
114
  : [] }) },
115
+ // NOTE: this does not return an iterable promise as we can't know
116
+ // what the user reduces to...
107
117
  reduce: function(func, res){
108
- return this.constructor(this.__list,
118
+ return this.constructor(this.__list.flat(),
109
119
  function(e){
110
120
  res = func(res, e)
111
121
  return [] })
112
122
  .then(function(){
113
123
  return res }) },
124
+ /*/ XXX this is wrong...
125
+ reduceRight: function(func, res){
126
+ return this.constructor(this.__list.flat().reverse(),
127
+ function(e){
128
+ res = func(res, e)
129
+ return [] })
130
+ .then(function(){
131
+ return res }) },
132
+ // XXX this is wrong...
133
+ reverse: function(){
134
+ return this.constructor(this.__list.flat().reverse()) },
114
135
  flat: function(depth=1){
115
- return this.constructor(this.__list,
136
+ return this.constructor(this.__list.flat(),
116
137
  function(e){
117
- return (e && e.flat) ?
118
- e.flat(depth)
119
- : e }) },
120
- // XXX do we need this???
121
- //iter: function(){
122
- // return this },
123
-
124
-
125
- // XXX do we need:
138
+ return (depth > 1
139
+ && e != null
140
+ && e.flat) ?
141
+ e.flat(depth-1)
142
+ : depth != 0 ?
143
+ e
144
+ : [e] }) },
145
+
146
+ // compatibility with root promise...
147
+ iter: function(){
148
+ return this.constructor(this.__list.flat()) },
149
+ //*/
150
+
151
+ // XXX do we need these?
126
152
  // .pop()
127
153
  // .shift()
128
154
  // .first() / .last()
@@ -204,9 +230,8 @@ object.Constructor('IterablePromise', Promise, {
204
230
  // - another issue here is that the stop would happen in order of
205
231
  // execution and not order of elements...
206
232
  __new__: function(_, list, handler){
207
- var promise
208
-
209
233
  // instance...
234
+ var promise
210
235
  var obj = Reflect.construct(
211
236
  IterablePromise.__proto__,
212
237
  [function(resolve, reject){
@@ -220,49 +245,29 @@ object.Constructor('IterablePromise', Promise, {
220
245
  IterablePromise)
221
246
 
222
247
  if(promise){
223
- //var __stop = false
224
- // apply handler(..) to the list...
225
- //
226
- // NOTE: the top level promises are not wrapped in arrays...
227
- list =
228
- // apply the handler...
229
- handler ?
230
- // XXX can we handle STOP here???
231
- // ...we will not be able to stop already started
232
- // promises...
233
- list.map(function(block){
234
- //* XXX STOP...
235
- return (block instanceof Array ?
236
- block
237
- : [block])
238
- /*/
239
- // NOTE: we are not using Array's .iter() so as to
240
- // keep the dependency minimal...
241
- return generator.iter(
242
- block instanceof Array ?
243
- block
244
- : [block])
245
- //*/
246
- .map(function(e){
247
- // NOTE: we are counting actual expanded
248
- // values and not the "blocks"...
249
- return (e && e.then && e.catch) ?
250
- // promise...
251
- e.then(function(v){
252
- return handler(v) })
253
- // basic value...
254
- : handler(e) }) })
255
- .flat()
256
- // XXX STOP
257
- //.toArray()
258
- // normal constructor...
259
- : handler === undefined ?
260
- list.map(function(e){
261
- return e instanceof Promise ?
262
- e
263
- : [e] })
264
- // clone...
265
- : list.slice()
248
+ // clone/normalize...
249
+ list = list
250
+ .map(function(e){
251
+ return (e && e.then) ?
252
+ e.then(function(e){
253
+ return [e] })
254
+ : [e] })
255
+
256
+ if(handler){
257
+ // NOTE: this is recursive to handle expanding nested promises...
258
+ var handle = function(elem){
259
+ // call the handler...
260
+ return (elem && elem.then) ?
261
+ elem.then(function(elems){
262
+ return elems
263
+ .map(handle)
264
+ .flat() })
265
+ : elem
266
+ .map(handler)
267
+ .flat() }
268
+
269
+ // handle the list...
270
+ list = list.map(handle) }
266
271
 
267
272
  Object.defineProperty(obj, '__list', {
268
273
  value: list,
@@ -417,6 +422,7 @@ object.Constructor('CooperativePromise', Promise, {
417
422
 
418
423
  //---------------------------------------------------------------------
419
424
 
425
+ // XXX EXPEREMENTAL...
420
426
  var ProxyPromise =
421
427
  module.ProxyPromise =
422
428
  object.Constructor('ProxyPromise', Promise, {
@@ -461,14 +467,6 @@ object.Constructor('ProxyPromise', Promise, {
461
467
 
462
468
  //---------------------------------------------------------------------
463
469
 
464
- // XXX EXPEREMENTAL...
465
- var PromiseProtoMixin =
466
- module.PromiseProtoMixin =
467
- object.Mixin('PromiseProtoMixin', 'soft', {
468
- as: ProxyPromise,
469
- })
470
-
471
-
472
470
  var PromiseMixin =
473
471
  module.PromiseMixin =
474
472
  object.Mixin('PromiseMixin', 'soft', {
@@ -479,7 +477,14 @@ object.Mixin('PromiseMixin', 'soft', {
479
477
 
480
478
  PromiseMixin(Promise)
481
479
 
480
+
482
481
  // XXX EXPEREMENTAL...
482
+ var PromiseProtoMixin =
483
+ module.PromiseProtoMixin =
484
+ object.Mixin('PromiseProtoMixin', 'soft', {
485
+ as: ProxyPromise,
486
+ })
487
+
483
488
  PromiseProtoMixin(Promise.prototype)
484
489
 
485
490
 
package/generator.js CHANGED
@@ -210,6 +210,7 @@ object.Mixin('GeneratorMixin', 'soft', {
210
210
  map: makeGenerator('map'),
211
211
  filter: makeGenerator('filter'),
212
212
  reduce: makeGenerator('reduce'),
213
+ reduceRight: makeGenerator('reduceRight'),
213
214
 
214
215
  // non-generators...
215
216
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-types",
3
- "version": "6.11.0",
3
+ "version": "6.11.1",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {