mol_dump_lib 0.0.214 → 0.0.215

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mol_dump_lib",
3
- "version": "0.0.214",
3
+ "version": "0.0.215",
4
4
  "exports": {
5
5
  "node": {
6
6
  "import": "./node.mjs",
package/web.test.js CHANGED
@@ -323,7 +323,12 @@ var $;
323
323
  var $;
324
324
  (function ($) {
325
325
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
326
- return new Proxy(new $mol_range2_array(), {
326
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
327
+ if (typeof item !== 'function') {
328
+ item = index => source[index];
329
+ size = () => source.length;
330
+ }
331
+ return new Proxy(source, {
327
332
  get(target, field) {
328
333
  if (typeof field === 'string') {
329
334
  if (field === 'length')
@@ -336,7 +341,7 @@ var $;
336
341
  if (index === Math.trunc(index))
337
342
  return item(index);
338
343
  }
339
- return target[field];
344
+ return $mol_range2_array.prototype[field];
340
345
  },
341
346
  set(target, field) {
342
347
  return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
@@ -377,13 +382,16 @@ var $;
377
382
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
378
383
  }
379
384
  filter(check, context) {
380
- const filtered = new $mol_range2_array();
381
- for (let index = 0; index < this.length; ++index) {
382
- const item = this[index];
383
- if (check.call(context, item, index, this))
384
- filtered.push(item);
385
- }
386
- return filtered;
385
+ const filtered = [];
386
+ let cursor = -1;
387
+ return $mol_range2(index => {
388
+ while (cursor < this.length && index >= filtered.length - 1) {
389
+ const val = this[++cursor];
390
+ if (check(val, cursor, this))
391
+ filtered.push(val);
392
+ }
393
+ return filtered[index];
394
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
387
395
  }
388
396
  forEach(proceed, context) {
389
397
  for (let [key, value] of this.entries())
@@ -443,7 +451,7 @@ var $;
443
451
  'lazy calls'() {
444
452
  let calls = 0;
445
453
  const list = $mol_range2(index => (++calls, index), () => 10);
446
- $mol_assert_ok(list instanceof Array);
454
+ $mol_assert_equal(true, list instanceof Array);
447
455
  $mol_assert_equal(list.length, 10);
448
456
  $mol_assert_equal(list[-1], undefined);
449
457
  $mol_assert_equal(list[0], 0);
@@ -486,11 +494,17 @@ var $;
486
494
  $mol_range2(i => i, () => 5).forEach(i => log += i);
487
495
  $mol_assert_equal(log, '01234');
488
496
  },
497
+ 'reduce'() {
498
+ let calls = 0;
499
+ const list = $mol_range2().slice(1, 6);
500
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
501
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
502
+ },
489
503
  'lazy concat'() {
490
504
  let calls1 = 0;
491
505
  let calls2 = 0;
492
506
  const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
493
- $mol_assert_ok(list instanceof Array);
507
+ $mol_assert_equal(true, list instanceof Array);
494
508
  $mol_assert_equal(list.length, 15);
495
509
  $mol_assert_equal(list[0], 0);
496
510
  $mol_assert_equal(list[4], 4);
@@ -502,32 +516,26 @@ var $;
502
516
  $mol_assert_equal(calls1, 2);
503
517
  $mol_assert_equal(calls2, 2);
504
518
  },
505
- 'filter'() {
519
+ 'lazy filter'() {
506
520
  let calls = 0;
507
- const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
508
- $mol_assert_ok(list instanceof Array);
521
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
522
+ $mol_assert_equal(true, list instanceof Array);
509
523
  $mol_assert_equal(list.length, 3);
510
524
  $mol_assert_equal(list[0], 1);
511
525
  $mol_assert_equal(list[2], 5);
512
526
  $mol_assert_equal(list[3], undefined);
513
- $mol_assert_equal(calls, 10);
527
+ $mol_assert_equal(calls, 8);
514
528
  },
515
- 'reverse'() {
529
+ 'lazy reverse'() {
516
530
  let calls = 0;
517
531
  const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
518
- $mol_assert_ok(list instanceof Array);
532
+ $mol_assert_equal(true, list instanceof Array);
519
533
  $mol_assert_equal(list.length, 3);
520
534
  $mol_assert_equal(list[0], 9);
521
535
  $mol_assert_equal(list[2], 7);
522
536
  $mol_assert_equal(list[3], undefined);
523
537
  $mol_assert_equal(calls, 2);
524
538
  },
525
- 'reduce'() {
526
- let calls = 0;
527
- const list = $mol_range2().slice(1, 6);
528
- $mol_assert_equal(list.reduce((s, v) => s + v), 15);
529
- $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
530
- },
531
539
  'lazy map'() {
532
540
  let calls1 = 0;
533
541
  let calls2 = 0;
@@ -537,7 +545,7 @@ var $;
537
545
  $mol_assert_equal(source, self);
538
546
  return index + 10;
539
547
  }, () => 5);
540
- $mol_assert_ok(target instanceof Array);
548
+ $mol_assert_equal(true, target instanceof Array);
541
549
  $mol_assert_equal(target.length, 5);
542
550
  $mol_assert_equal(target[0], 10);
543
551
  $mol_assert_equal(target[4], 14);
@@ -548,7 +556,7 @@ var $;
548
556
  'lazy slice'() {
549
557
  let calls = 0;
550
558
  const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
551
- $mol_assert_ok(list instanceof Array);
559
+ $mol_assert_equal(true, list instanceof Array);
552
560
  $mol_assert_equal(list.length, 4);
553
561
  $mol_assert_equal(list[0], 3);
554
562
  $mol_assert_equal(list[3], 6);
@@ -557,22 +565,22 @@ var $;
557
565
  },
558
566
  'lazy some'() {
559
567
  let calls = 0;
560
- $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
568
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
561
569
  $mol_assert_equal(calls, 3);
562
- $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
563
- $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
570
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
571
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
564
572
  },
565
573
  'lazy every'() {
566
574
  let calls = 0;
567
- $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
575
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
568
576
  $mol_assert_equal(calls, 3);
569
- $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
570
- $mol_assert_not($mol_range2(i => i).every(v => v < 5));
577
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
578
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
571
579
  },
572
580
  'lazyfy'() {
573
581
  let calls = 0;
574
- const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
575
- $mol_assert_ok(list instanceof Array);
582
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
583
+ $mol_assert_equal(true, list instanceof Array);
576
584
  $mol_assert_equal(list.length, 4);
577
585
  $mol_assert_equal(calls, 0);
578
586
  $mol_assert_equal(list[0], 12);