ig-types 6.16.4 → 6.19.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/Array.js CHANGED
@@ -482,6 +482,35 @@ object.Mixin('ArrayProtoMixin', 'soft', {
482
482
  this.constructor.zip(this, func, ...arrays)
483
483
  : this.constructor.zip(func, this, ...arrays) },
484
484
 
485
+ // Insert new values between elements of an array
486
+ //
487
+ // .between(value)
488
+ // -> array
489
+ //
490
+ // .between(func)
491
+ // -> array
492
+ //
493
+ // func([a, b], from_index, to_index, array)
494
+ // -> elem
495
+ //
496
+ between: function(func){
497
+ var res = []
498
+ // NOTE: we skip the last element...
499
+ for(var i=0; i < this.length; i+=1){
500
+ var pair = new Array(2)
501
+ i in this ?
502
+ res.push(pair[0] = this[i])
503
+ : (res.length += 1)
504
+ if(i+1 >= this.length){
505
+ break }
506
+ i+1 in this
507
+ && (pair[1] = this[i+1])
508
+ res.push(
509
+ typeof(func) == 'function' ?
510
+ func.call(this, pair, i, res.length, this)
511
+ : func) }
512
+ return res },
513
+
485
514
  // get iterator over array...
486
515
  //
487
516
  // Array.iter()
package/Promise.js CHANGED
@@ -249,6 +249,15 @@ object.Constructor('IterablePromise', Promise, {
249
249
  : (await Promise.all(list))
250
250
  .flat() },
251
251
 
252
+ [Symbol.asyncIterator]: async function*(){
253
+ var list = this.__packed
254
+ if(list instanceof Promise){
255
+ yield this.__unpack(await list)
256
+ return }
257
+ for await(var elem of list){
258
+ yield* elem instanceof Array ?
259
+ elem
260
+ : [elem] } },
252
261
 
253
262
  // iterator methods...
254
263
  //
@@ -294,6 +303,22 @@ object.Constructor('IterablePromise', Promise, {
294
303
  .then(function(){
295
304
  return res }) },
296
305
 
306
+ // XXX BETWEEN...
307
+ between: function(func){
308
+ var i = 0
309
+ var j = 0
310
+ var prev
311
+ return this.constructor(this,
312
+ function(e){
313
+ return i++ > 0 ?
314
+ [
315
+ typeof(func) == 'function' ?
316
+ func.call(this, [prev, e], i, i + j++)
317
+ : func,
318
+ e,
319
+ ]
320
+ : [e] }) },
321
+
297
322
  // XXX .chain(..) -- see generator.chain(..)
298
323
 
299
324
  flat: function(depth=1){
package/README.md CHANGED
@@ -30,6 +30,7 @@ Library of JavaScript type extensions, types and utilities.
30
30
  - [`<array>.toMap(..)`](#arraytomap)
31
31
  - [`Array.zip(..)` / `<array>.zip(..)`](#arrayzip--arrayzip)
32
32
  - [`Array.iter(..)` / `<array>.iter()`](#arrayiter--arrayiter)
33
+ - [`<array>.between(..)`](#arraybetween)
33
34
  - [Abortable `Array` iteration](#abortable-array-iteration)
34
35
  - [`array.STOP` / `array.STOP(..)`](#arraystop--arraystop)
35
36
  - [`<array>.smap(..)` / `<array>.sfilter(..)` / `<array>.sreduce(..)` / `<array>.sforEach(..)`](#arraysmap--arraysfilter--arraysreduce--arraysforeach)
@@ -48,6 +49,7 @@ Library of JavaScript type extensions, types and utilities.
48
49
  - [`<set>.replace(..)`](#setreplace)
49
50
  - [`<set>.replaceAt(..)`](#setreplaceat)
50
51
  - [`<set>.sort(..)`](#setsort)
52
+ - [`<set>.filter(..)` / `<set>.map(..)` / `<set>.forEach(..)` / `<set>.reduce(..)` / `<set>.reduceRight(..)`](#setfilter--setmap--setforeach--setreduce--setreduceright)
51
53
  - [`Date`](#date)
52
54
  - [`Date.timeStamp(..)`](#datetimestamp)
53
55
  - [`Date.fromTimeStamp(..)`](#datefromtimestamp)
@@ -75,6 +77,7 @@ Library of JavaScript type extensions, types and utilities.
75
77
  - [`<promise>.iter()`](#promiseiter)
76
78
  - [`<promise-iter>.iter()`](#promise-iteriter)
77
79
  - [`<promise-iter>.map(..)` / `<promise-iter>.filter(..)` / `<promise-iter>.reduce(..)`](#promise-itermap--promise-iterfilter--promise-iterreduce)
80
+ - [`<promise-iter>.between(..)`](#promise-iterbetween)
78
81
  - [`<promise-iter>.flat(..)`](#promise-iterflat)
79
82
  - [`<promise-iter>.reverse()`](#promise-iterreverse)
80
83
  - [`<promise-iter>.concat(..)`](#promise-iterconcat)
@@ -100,7 +103,8 @@ Library of JavaScript type extensions, types and utilities.
100
103
  - [`<generator>.iter(..)`](#generatoriter-1)
101
104
  - [`<generator>.map(..)` / `<generator>.filter(..)`](#generatormap--generatorfilter)
102
105
  - [`<generator>.reduce(..)` / `<generator>.greduce(..)`](#generatorreduce--generatorgreduce)
103
- - [`<generator>.forEach(..)`](#generatorforeach)
106
+ - [`<generator>.forEach(..)` (EXPERIMENTAL)](#generatorforeach-experimental)
107
+ - [`<generator>.between(..)`](#generatorbetween)
104
108
  - [`<generator>.slice(..)`](#generatorslice)
105
109
  - [`<generator>.at(..)` / `<generator>.gat(..)`](#generatorat--generatorgat)
106
110
  - [`<generator>.flat(..)`](#generatorflat)
@@ -117,6 +121,7 @@ Library of JavaScript type extensions, types and utilities.
117
121
  - [`<generator>.unshift(..)` / `<generator>.push(..)`](#generatorunshift--generatorpush-1)
118
122
  - [`<Generator>.slice(..)`](#generatorslice-1)
119
123
  - [`<Generator>.map(..)` / `<Generator>.filter(..)` / `<Generator>.reduce(..)` / `<Generator>.flat()`](#generatormap--generatorfilter--generatorreduce--generatorflat)
124
+ - [`<Generator>.between(..)`](#generatorbetween-1)
120
125
  - [`<Generator>.toArray()`](#generatortoarray-1)
121
126
  - [`<Generator>.join(..)`](#generatorjoin-1)
122
127
  - [`<Generator>.then(..)` / `<Generator>.catch(..)` / `<Generator>.finally(..)`](#generatorthen--generatorcatch--generatorfinally-1)
@@ -737,6 +742,19 @@ Return an iterator/generator from the current array.
737
742
  This is mostly useful in combination with the [Generator extensions and utilities](#generator-extensions-and-utilities)
738
743
 
739
744
 
745
+ ### `<array>.between(..)`
746
+
747
+ ```bnf
748
+ <array>.between(<value>)
749
+ -> <array>
750
+ <array>.between(<func>)
751
+ -> <array>
752
+
753
+ <func>([<pre>, <post>], <index-in>, <index-out>, <array>)
754
+ -> <value>
755
+ ```
756
+
757
+
740
758
  ### Abortable `Array` iteration
741
759
 
742
760
  A an alternative to `Array`'s `.map(..)` / `.filter(..)` / .. methods with ability to
@@ -1077,6 +1095,12 @@ This is similar to [`<map>.sort(..)`](#mapsort) and [`Object.sort(..)`](#objects
1077
1095
  see the later for more info.
1078
1096
 
1079
1097
 
1098
+ ### `<set>.filter(..)` / `<set>.map(..)` / `<set>.forEach(..)` / `<set>.reduce(..)` / `<set>.reduceRight(..)`
1099
+
1100
+ For more info see corresponding stoppable methods in
1101
+ [`Array`'s section](#arraysmap--arraysfilter--arraysreduce--arraysforeach).
1102
+
1103
+
1080
1104
 
1081
1105
  ## `Date`
1082
1106
 
@@ -1563,6 +1587,14 @@ in how they process values:
1563
1587
  appropriate method on the result.
1564
1588
  <!-- XXX list + mark definitions as "(proxy)" -->
1565
1589
 
1590
+ Promise iterators directly support _for-await-of_ iteration:
1591
+
1592
+ ```javascript
1593
+ for await (var elem of Promise.iter(/* ... */)){
1594
+ // ...
1595
+ }
1596
+ ```
1597
+
1566
1598
  <!--
1567
1599
  XXX should we support generators as input?
1568
1600
  ...not sure about the control flow direction here, on one hand the generator
@@ -1658,6 +1690,19 @@ Note that since `.reduce(..)` handler's execution order can not be known,
1658
1690
  there is no point in implementing `.reduceRigth(..)`.
1659
1691
 
1660
1692
 
1693
+ ### `<promise-iter>.between(..)`
1694
+
1695
+ ```bnf
1696
+ <promise-iter>.between(<value>)
1697
+ -> <promise-iter>
1698
+ <promise-iter>.between(<func>)
1699
+ -> <promise-iter>
1700
+
1701
+ <func>([<pre>, <post>], <index-in>, <index-out>, <promise-iter>)
1702
+ -> <value>
1703
+ ```
1704
+
1705
+
1661
1706
  #### `<promise-iter>.flat(..)`
1662
1707
 
1663
1708
  ```bnf
@@ -2136,7 +2181,7 @@ XXX .reduce(..) can return a non-iterable -- test and document this case...
2136
2181
  ...compare with Array.prototype.reduce(..)
2137
2182
  -->
2138
2183
 
2139
- #### `<generator>.forEach(..)`
2184
+ #### `<generator>.forEach(..)` (EXPERIMENTAL)
2140
2185
 
2141
2186
  ```bnf
2142
2187
  <generator>.forEach(<func>)
@@ -2145,7 +2190,21 @@ XXX .reduce(..) can return a non-iterable -- test and document this case...
2145
2190
 
2146
2191
  This is different from the above in that this will unwind the `<generator>`.
2147
2192
 
2148
- Note that this differs from `<array>.forEach(..)` in that his will return the resulting array, essentially behaving like `.map(..)`.
2193
+ Note that this differs from `<array>.forEach(..)` in that his will return the
2194
+ resulting array, essentially behaving like `.map(..)`.
2195
+
2196
+
2197
+ #### `<generator>.between(..)`
2198
+
2199
+ ```bnf
2200
+ <generator>.between(<value>)
2201
+ -> <generator>
2202
+ <generator>.between(<func>)
2203
+ -> <generator>
2204
+
2205
+ <func>([<pre>, <post>], <index-in>, <index-out>, <generator>)
2206
+ -> <value>
2207
+ ```
2149
2208
 
2150
2209
 
2151
2210
  #### `<generator>.slice(..)`
@@ -2428,6 +2487,19 @@ but return a `<Generator>`.
2428
2487
  <!-- XXX -->
2429
2488
 
2430
2489
 
2490
+ #### `<Generator>.between(..)`
2491
+
2492
+ ```bnf
2493
+ <Generator>.between(<value>)
2494
+ -> <Generator>
2495
+ <Generator>.between(<func>)
2496
+ -> <Generator>
2497
+
2498
+ <func>([<pre>, <post>], <index-in>, <index-out>, <Generator>)
2499
+ -> <value>
2500
+ ```
2501
+
2502
+
2431
2503
  #### `<Generator>.toArray()`
2432
2504
 
2433
2505
  Return a function that will return a `<generator>` output as an `Array`.
package/Set.js CHANGED
@@ -8,11 +8,29 @@
8
8
  /*********************************************************************/
9
9
 
10
10
  var object = require('ig-object')
11
+ var stoppable = require('ig-stoppable')
11
12
 
12
13
 
13
14
 
14
15
  /*********************************************************************/
15
16
 
17
+ // Wrap .map(..) / .filter(..) / .reduce(..) / .. to support STOP...
18
+ //
19
+ // NOTE: internally these are implemented as for-of loops (./generator.js)
20
+ var stoppableSet = function(iter){
21
+ return function(func){
22
+ return new Set([...this][iter](...arguments)) } }
23
+ var stoppableValue = function(iter, no_return=false){
24
+ return function(func){
25
+ var res = [...this][iter](...arguments)
26
+ return no_return ?
27
+ undefined
28
+ : res } }
29
+
30
+
31
+
32
+ //---------------------------------------------------------------------
33
+
16
34
  var SetProtoMixin =
17
35
  module.SetProtoMixin =
18
36
  object.Mixin('SetMixin', 'soft', {
@@ -110,6 +128,12 @@ object.Mixin('SetMixin', 'soft', {
110
128
  this.sort(order)
111
129
 
112
130
  return removed },
131
+
132
+ filter: stoppableSet('filter'),
133
+ map: stoppableSet('map'),
134
+ reduce: stoppableValue('reduce'),
135
+ reduceRight: stoppableValue('reduceRight'),
136
+ forEach: stoppableValue('map', true),
113
137
  })
114
138
 
115
139
 
package/generator.js CHANGED
@@ -223,7 +223,10 @@ object.Mixin('GeneratorMixin', 'soft', {
223
223
  reduce: makeGenerator('reduce'),
224
224
  reduceRight: makeGenerator('reduceRight'),
225
225
 
226
- // XXX add .toString(..) ???
226
+ between: makeGenerator('between'),
227
+
228
+ // XXX EXPERIMENTAL
229
+ // XXX add .toString(..) to this???
227
230
  forEach: function(func){
228
231
  var that = this
229
232
  return function(){
@@ -403,9 +406,23 @@ object.Mixin('GeneratorProtoMixin', 'soft', {
403
406
  greduce: function*(func, res){
404
407
  yield this.reduce(...arguments) },
405
408
 
409
+ between: stoppable(function*(func){
410
+ var i = 0
411
+ var j = 0
412
+ var prev
413
+ for(var e of this){
414
+ if(i > 0){
415
+ yield typeof(func) == 'function' ?
416
+ func.call(this, [prev, e], i-1, i + j++, this)
417
+ : func }
418
+ prev = e
419
+ yield e
420
+ i++ } }),
421
+
406
422
  // NOTE: this is a special case in that it will unwind the generator...
407
423
  // NOTE: this is different from <array>.forEach(..) in that this will
408
424
  // return the resulting array.
425
+ // XXX EXPERIMENTAL
409
426
  forEach: function(func){
410
427
  return [...this].map(func) },
411
428
 
@@ -502,6 +519,9 @@ object.Mixin('AsyncGeneratorMixin', 'soft', {
502
519
  map: makeGenerator('async', 'map'),
503
520
  filter: makeGenerator('async', 'filter'),
504
521
  reduce: makeGenerator('async', 'reduce'),
522
+
523
+ // XXX TEST...
524
+ between: makeGenerator('async', 'between'),
505
525
  })
506
526
 
507
527
  var AsyncGeneratorProtoMixin =
@@ -559,6 +579,21 @@ object.Mixin('AsyncGeneratorProtoMixin', 'soft', {
559
579
  return [] })
560
580
  return state },
561
581
 
582
+ // XXX BETWEEN...
583
+ between: async function*(func){
584
+ var i = 0
585
+ var j = 0
586
+ var prev
587
+ yield* this.iter(function(e){
588
+ return i++ > 0 ?
589
+ [
590
+ typeof(func) == 'function' ?
591
+ func.call(this, [prev, e], i, i + j++, this)
592
+ : func,
593
+ e,
594
+ ]
595
+ : [e] }) },
596
+
562
597
  // XXX TEST...
563
598
  chain: async function*(...next){
564
599
  yield* next
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-types",
3
- "version": "6.16.4",
3
+ "version": "6.19.0",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {