ig-types 6.16.2 → 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,6 +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)
105
+ - [`<generator>.forEach(..)` (EXPERIMENTAL)](#generatorforeach-experimental)
106
+ - [`<generator>.between(..)`](#generatorbetween)
103
107
  - [`<generator>.slice(..)`](#generatorslice)
104
108
  - [`<generator>.at(..)` / `<generator>.gat(..)`](#generatorat--generatorgat)
105
109
  - [`<generator>.flat(..)`](#generatorflat)
@@ -116,6 +120,7 @@ Library of JavaScript type extensions, types and utilities.
116
120
  - [`<generator>.unshift(..)` / `<generator>.push(..)`](#generatorunshift--generatorpush-1)
117
121
  - [`<Generator>.slice(..)`](#generatorslice-1)
118
122
  - [`<Generator>.map(..)` / `<Generator>.filter(..)` / `<Generator>.reduce(..)` / `<Generator>.flat()`](#generatormap--generatorfilter--generatorreduce--generatorflat)
123
+ - [`<Generator>.between(..)`](#generatorbetween-1)
119
124
  - [`<Generator>.toArray()`](#generatortoarray-1)
120
125
  - [`<Generator>.join(..)`](#generatorjoin-1)
121
126
  - [`<Generator>.then(..)` / `<Generator>.catch(..)` / `<Generator>.finally(..)`](#generatorthen--generatorcatch--generatorfinally-1)
@@ -736,6 +741,19 @@ Return an iterator/generator from the current array.
736
741
  This is mostly useful in combination with the [Generator extensions and utilities](#generator-extensions-and-utilities)
737
742
 
738
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
+
739
757
  ### Abortable `Array` iteration
740
758
 
741
759
  A an alternative to `Array`'s `.map(..)` / `.filter(..)` / .. methods with ability to
@@ -1657,6 +1675,19 @@ Note that since `.reduce(..)` handler's execution order can not be known,
1657
1675
  there is no point in implementing `.reduceRigth(..)`.
1658
1676
 
1659
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
+
1660
1691
  #### `<promise-iter>.flat(..)`
1661
1692
 
1662
1693
  ```bnf
@@ -2135,6 +2166,31 @@ XXX .reduce(..) can return a non-iterable -- test and document this case...
2135
2166
  ...compare with Array.prototype.reduce(..)
2136
2167
  -->
2137
2168
 
2169
+ #### `<generator>.forEach(..)` (EXPERIMENTAL)
2170
+
2171
+ ```bnf
2172
+ <generator>.forEach(<func>)
2173
+ -> <array>
2174
+ ```
2175
+
2176
+ This is different from the above in that this will unwind the `<generator>`.
2177
+
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
+ ```
2193
+
2138
2194
 
2139
2195
  #### `<generator>.slice(..)`
2140
2196
 
@@ -2416,6 +2472,19 @@ but return a `<Generator>`.
2416
2472
  <!-- XXX -->
2417
2473
 
2418
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
+
2419
2488
  #### `<Generator>.toArray()`
2420
2489
 
2421
2490
  Return a function that will return a `<generator>` output as an `Array`.
package/event.js CHANGED
@@ -132,9 +132,12 @@ object.Constructor('Eventful', {
132
132
  return this },
133
133
  unbind: function(context, handler){
134
134
  var handlers =
135
- (this.handlerLocation == 'method' ?
135
+ this.handlerLocation == 'method' ?
136
136
  method.__event_handlers__
137
- : (context.__event_handlers__ || {})[this.name]) || []
137
+ //: (context.__event_handlers__ || {})[this.name]) || []
138
+ : context.hasOwnProperty('__event_handlers__') ?
139
+ (context.__event_handlers__ || {})[this.name] || []
140
+ : []
138
141
  handlers.splice(0, handlers.length,
139
142
  ...handlers.filter(function(h){
140
143
  return h !== handler
@@ -150,7 +153,10 @@ object.Constructor('Eventful', {
150
153
  // context (default)...
151
154
  // NOTE: these are allways called...
152
155
  handlers = handlers
153
- .concat((context.__event_handlers__ || {})[this.name] || [])
156
+ //.concat((context.__event_handlers__ || {})[this.name] || [])
157
+ .concat(context.hasOwnProperty('__event_handlers__') ?
158
+ (context.__event_handlers__ || {})[this.name] || []
159
+ : [])
154
160
 
155
161
  // NOTE: this will stop event handling if one of the handlers
156
162
  // explicitly returns false...
@@ -334,7 +340,8 @@ module.EventHandlerMixin = object.Mixin('EventHandlerMixin', {
334
340
  evt in this ?
335
341
  // XXX add a better check...
336
342
  this[evt](module.TRIGGER, ...args)
337
- : this.__event_handlers__
343
+ //: this.__event_handlers__
344
+ : this.hasOwnProperty('__event_handlers__')
338
345
  && (this.__event_handlers__[evt] || [])
339
346
  .forEach(function(h){ h(evt, ...args) })
340
347
  return this },
package/generator.js CHANGED
@@ -223,6 +223,15 @@ object.Mixin('GeneratorMixin', 'soft', {
223
223
  reduce: makeGenerator('reduce'),
224
224
  reduceRight: makeGenerator('reduceRight'),
225
225
 
226
+ between: makeGenerator('between'),
227
+
228
+ // XXX EXPERIMENTAL
229
+ // XXX add .toString(..) to this???
230
+ forEach: function(func){
231
+ var that = this
232
+ return function(){
233
+ return that(...arguments).forEach(func) } },
234
+
226
235
  // non-generators...
227
236
  //
228
237
  toArray: function(){
@@ -397,6 +406,26 @@ object.Mixin('GeneratorProtoMixin', 'soft', {
397
406
  greduce: function*(func, res){
398
407
  yield this.reduce(...arguments) },
399
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
+
422
+ // NOTE: this is a special case in that it will unwind the generator...
423
+ // NOTE: this is different from <array>.forEach(..) in that this will
424
+ // return the resulting array.
425
+ // XXX EXPERIMENTAL
426
+ forEach: function(func){
427
+ return [...this].map(func) },
428
+
400
429
  pop: function(){
401
430
  return [...this].pop() },
402
431
  // XXX this needs the value to be iterable...
@@ -490,6 +519,9 @@ object.Mixin('AsyncGeneratorMixin', 'soft', {
490
519
  map: makeGenerator('async', 'map'),
491
520
  filter: makeGenerator('async', 'filter'),
492
521
  reduce: makeGenerator('async', 'reduce'),
522
+
523
+ // XXX TEST...
524
+ between: makeGenerator('async', 'between'),
493
525
  })
494
526
 
495
527
  var AsyncGeneratorProtoMixin =
@@ -547,6 +579,21 @@ object.Mixin('AsyncGeneratorProtoMixin', 'soft', {
547
579
  return [] })
548
580
  return state },
549
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
+
550
597
  // XXX TEST...
551
598
  chain: async function*(...next){
552
599
  yield* next
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-types",
3
- "version": "6.16.2",
3
+ "version": "6.17.0",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {