ig-types 6.16.4 → 6.17.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
@@ -294,6 +294,22 @@ object.Constructor('IterablePromise', Promise, {
294
294
  .then(function(){
295
295
  return res }) },
296
296
 
297
+ // XXX BETWEEN...
298
+ between: function(func){
299
+ var i = 0
300
+ var j = 0
301
+ var prev
302
+ return this.constructor(this,
303
+ function(e){
304
+ return i++ > 0 ?
305
+ [
306
+ typeof(func) == 'function' ?
307
+ func.call(this, [prev, e], i, i + j++)
308
+ : func,
309
+ e,
310
+ ]
311
+ : [e] }) },
312
+
297
313
  // XXX .chain(..) -- see generator.chain(..)
298
314
 
299
315
  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)
@@ -75,6 +76,7 @@ Library of JavaScript type extensions, types and utilities.
75
76
  - [`<promise>.iter()`](#promiseiter)
76
77
  - [`<promise-iter>.iter()`](#promise-iteriter)
77
78
  - [`<promise-iter>.map(..)` / `<promise-iter>.filter(..)` / `<promise-iter>.reduce(..)`](#promise-itermap--promise-iterfilter--promise-iterreduce)
79
+ - [`<promise-iter>.between(..)`](#promise-iterbetween)
78
80
  - [`<promise-iter>.flat(..)`](#promise-iterflat)
79
81
  - [`<promise-iter>.reverse()`](#promise-iterreverse)
80
82
  - [`<promise-iter>.concat(..)`](#promise-iterconcat)
@@ -100,7 +102,8 @@ Library of JavaScript type extensions, types and utilities.
100
102
  - [`<generator>.iter(..)`](#generatoriter-1)
101
103
  - [`<generator>.map(..)` / `<generator>.filter(..)`](#generatormap--generatorfilter)
102
104
  - [`<generator>.reduce(..)` / `<generator>.greduce(..)`](#generatorreduce--generatorgreduce)
103
- - [`<generator>.forEach(..)`](#generatorforeach)
105
+ - [`<generator>.forEach(..)` (EXPERIMENTAL)](#generatorforeach-experimental)
106
+ - [`<generator>.between(..)`](#generatorbetween)
104
107
  - [`<generator>.slice(..)`](#generatorslice)
105
108
  - [`<generator>.at(..)` / `<generator>.gat(..)`](#generatorat--generatorgat)
106
109
  - [`<generator>.flat(..)`](#generatorflat)
@@ -117,6 +120,7 @@ Library of JavaScript type extensions, types and utilities.
117
120
  - [`<generator>.unshift(..)` / `<generator>.push(..)`](#generatorunshift--generatorpush-1)
118
121
  - [`<Generator>.slice(..)`](#generatorslice-1)
119
122
  - [`<Generator>.map(..)` / `<Generator>.filter(..)` / `<Generator>.reduce(..)` / `<Generator>.flat()`](#generatormap--generatorfilter--generatorreduce--generatorflat)
123
+ - [`<Generator>.between(..)`](#generatorbetween-1)
120
124
  - [`<Generator>.toArray()`](#generatortoarray-1)
121
125
  - [`<Generator>.join(..)`](#generatorjoin-1)
122
126
  - [`<Generator>.then(..)` / `<Generator>.catch(..)` / `<Generator>.finally(..)`](#generatorthen--generatorcatch--generatorfinally-1)
@@ -737,6 +741,19 @@ Return an iterator/generator from the current array.
737
741
  This is mostly useful in combination with the [Generator extensions and utilities](#generator-extensions-and-utilities)
738
742
 
739
743
 
744
+ ### `<array>.between(..)`
745
+
746
+ ```bnf
747
+ <array>.between(<value>)
748
+ -> <array>
749
+ <array>.between(<func>)
750
+ -> <array>
751
+
752
+ <func>([<pre>, <post>], <index-in>, <index-out>, <array>)
753
+ -> <value>
754
+ ```
755
+
756
+
740
757
  ### Abortable `Array` iteration
741
758
 
742
759
  A an alternative to `Array`'s `.map(..)` / `.filter(..)` / .. methods with ability to
@@ -1658,6 +1675,19 @@ Note that since `.reduce(..)` handler's execution order can not be known,
1658
1675
  there is no point in implementing `.reduceRigth(..)`.
1659
1676
 
1660
1677
 
1678
+ ### `<promise-iter>.between(..)`
1679
+
1680
+ ```bnf
1681
+ <promise-iter>.between(<value>)
1682
+ -> <promise-iter>
1683
+ <promise-iter>.between(<func>)
1684
+ -> <promise-iter>
1685
+
1686
+ <func>([<pre>, <post>], <index-in>, <index-out>, <promise-iter>)
1687
+ -> <value>
1688
+ ```
1689
+
1690
+
1661
1691
  #### `<promise-iter>.flat(..)`
1662
1692
 
1663
1693
  ```bnf
@@ -2136,7 +2166,7 @@ XXX .reduce(..) can return a non-iterable -- test and document this case...
2136
2166
  ...compare with Array.prototype.reduce(..)
2137
2167
  -->
2138
2168
 
2139
- #### `<generator>.forEach(..)`
2169
+ #### `<generator>.forEach(..)` (EXPERIMENTAL)
2140
2170
 
2141
2171
  ```bnf
2142
2172
  <generator>.forEach(<func>)
@@ -2145,7 +2175,21 @@ XXX .reduce(..) can return a non-iterable -- test and document this case...
2145
2175
 
2146
2176
  This is different from the above in that this will unwind the `<generator>`.
2147
2177
 
2148
- Note that this differs from `<array>.forEach(..)` in that his will return the resulting array, essentially behaving like `.map(..)`.
2178
+ Note that this differs from `<array>.forEach(..)` in that his will return the
2179
+ resulting array, essentially behaving like `.map(..)`.
2180
+
2181
+
2182
+ #### `<generator>.between(..)`
2183
+
2184
+ ```bnf
2185
+ <generator>.between(<value>)
2186
+ -> <generator>
2187
+ <generator>.between(<func>)
2188
+ -> <generator>
2189
+
2190
+ <func>([<pre>, <post>], <index-in>, <index-out>, <generator>)
2191
+ -> <value>
2192
+ ```
2149
2193
 
2150
2194
 
2151
2195
  #### `<generator>.slice(..)`
@@ -2428,6 +2472,19 @@ but return a `<Generator>`.
2428
2472
  <!-- XXX -->
2429
2473
 
2430
2474
 
2475
+ #### `<Generator>.between(..)`
2476
+
2477
+ ```bnf
2478
+ <Generator>.between(<value>)
2479
+ -> <Generator>
2480
+ <Generator>.between(<func>)
2481
+ -> <Generator>
2482
+
2483
+ <func>([<pre>, <post>], <index-in>, <index-out>, <Generator>)
2484
+ -> <value>
2485
+ ```
2486
+
2487
+
2431
2488
  #### `<Generator>.toArray()`
2432
2489
 
2433
2490
  Return a function that will return a `<generator>` output as an `Array`.
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.17.0",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {