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/node.test.js CHANGED
@@ -6925,7 +6925,12 @@ var $;
6925
6925
  var $;
6926
6926
  (function ($) {
6927
6927
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
6928
- return new Proxy(new $mol_range2_array(), {
6928
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
6929
+ if (typeof item !== 'function') {
6930
+ item = index => source[index];
6931
+ size = () => source.length;
6932
+ }
6933
+ return new Proxy(source, {
6929
6934
  get(target, field) {
6930
6935
  if (typeof field === 'string') {
6931
6936
  if (field === 'length')
@@ -6938,7 +6943,7 @@ var $;
6938
6943
  if (index === Math.trunc(index))
6939
6944
  return item(index);
6940
6945
  }
6941
- return target[field];
6946
+ return $mol_range2_array.prototype[field];
6942
6947
  },
6943
6948
  set(target, field) {
6944
6949
  return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
@@ -6979,13 +6984,16 @@ var $;
6979
6984
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
6980
6985
  }
6981
6986
  filter(check, context) {
6982
- const filtered = new $mol_range2_array();
6983
- for (let index = 0; index < this.length; ++index) {
6984
- const item = this[index];
6985
- if (check.call(context, item, index, this))
6986
- filtered.push(item);
6987
- }
6988
- return filtered;
6987
+ const filtered = [];
6988
+ let cursor = -1;
6989
+ return $mol_range2(index => {
6990
+ while (cursor < this.length && index >= filtered.length - 1) {
6991
+ const val = this[++cursor];
6992
+ if (check(val, cursor, this))
6993
+ filtered.push(val);
6994
+ }
6995
+ return filtered[index];
6996
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
6989
6997
  }
6990
6998
  forEach(proceed, context) {
6991
6999
  for (let [key, value] of this.entries())
@@ -7045,7 +7053,7 @@ var $;
7045
7053
  'lazy calls'() {
7046
7054
  let calls = 0;
7047
7055
  const list = $mol_range2(index => (++calls, index), () => 10);
7048
- $mol_assert_ok(list instanceof Array);
7056
+ $mol_assert_equal(true, list instanceof Array);
7049
7057
  $mol_assert_equal(list.length, 10);
7050
7058
  $mol_assert_equal(list[-1], undefined);
7051
7059
  $mol_assert_equal(list[0], 0);
@@ -7088,11 +7096,17 @@ var $;
7088
7096
  $mol_range2(i => i, () => 5).forEach(i => log += i);
7089
7097
  $mol_assert_equal(log, '01234');
7090
7098
  },
7099
+ 'reduce'() {
7100
+ let calls = 0;
7101
+ const list = $mol_range2().slice(1, 6);
7102
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
7103
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
7104
+ },
7091
7105
  'lazy concat'() {
7092
7106
  let calls1 = 0;
7093
7107
  let calls2 = 0;
7094
7108
  const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
7095
- $mol_assert_ok(list instanceof Array);
7109
+ $mol_assert_equal(true, list instanceof Array);
7096
7110
  $mol_assert_equal(list.length, 15);
7097
7111
  $mol_assert_equal(list[0], 0);
7098
7112
  $mol_assert_equal(list[4], 4);
@@ -7104,32 +7118,26 @@ var $;
7104
7118
  $mol_assert_equal(calls1, 2);
7105
7119
  $mol_assert_equal(calls2, 2);
7106
7120
  },
7107
- 'filter'() {
7121
+ 'lazy filter'() {
7108
7122
  let calls = 0;
7109
- const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
7110
- $mol_assert_ok(list instanceof Array);
7123
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
7124
+ $mol_assert_equal(true, list instanceof Array);
7111
7125
  $mol_assert_equal(list.length, 3);
7112
7126
  $mol_assert_equal(list[0], 1);
7113
7127
  $mol_assert_equal(list[2], 5);
7114
7128
  $mol_assert_equal(list[3], undefined);
7115
- $mol_assert_equal(calls, 10);
7129
+ $mol_assert_equal(calls, 8);
7116
7130
  },
7117
- 'reverse'() {
7131
+ 'lazy reverse'() {
7118
7132
  let calls = 0;
7119
7133
  const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
7120
- $mol_assert_ok(list instanceof Array);
7134
+ $mol_assert_equal(true, list instanceof Array);
7121
7135
  $mol_assert_equal(list.length, 3);
7122
7136
  $mol_assert_equal(list[0], 9);
7123
7137
  $mol_assert_equal(list[2], 7);
7124
7138
  $mol_assert_equal(list[3], undefined);
7125
7139
  $mol_assert_equal(calls, 2);
7126
7140
  },
7127
- 'reduce'() {
7128
- let calls = 0;
7129
- const list = $mol_range2().slice(1, 6);
7130
- $mol_assert_equal(list.reduce((s, v) => s + v), 15);
7131
- $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
7132
- },
7133
7141
  'lazy map'() {
7134
7142
  let calls1 = 0;
7135
7143
  let calls2 = 0;
@@ -7139,7 +7147,7 @@ var $;
7139
7147
  $mol_assert_equal(source, self);
7140
7148
  return index + 10;
7141
7149
  }, () => 5);
7142
- $mol_assert_ok(target instanceof Array);
7150
+ $mol_assert_equal(true, target instanceof Array);
7143
7151
  $mol_assert_equal(target.length, 5);
7144
7152
  $mol_assert_equal(target[0], 10);
7145
7153
  $mol_assert_equal(target[4], 14);
@@ -7150,7 +7158,7 @@ var $;
7150
7158
  'lazy slice'() {
7151
7159
  let calls = 0;
7152
7160
  const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
7153
- $mol_assert_ok(list instanceof Array);
7161
+ $mol_assert_equal(true, list instanceof Array);
7154
7162
  $mol_assert_equal(list.length, 4);
7155
7163
  $mol_assert_equal(list[0], 3);
7156
7164
  $mol_assert_equal(list[3], 6);
@@ -7159,22 +7167,22 @@ var $;
7159
7167
  },
7160
7168
  'lazy some'() {
7161
7169
  let calls = 0;
7162
- $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
7170
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
7163
7171
  $mol_assert_equal(calls, 3);
7164
- $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
7165
- $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
7172
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
7173
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
7166
7174
  },
7167
7175
  'lazy every'() {
7168
7176
  let calls = 0;
7169
- $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
7177
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
7170
7178
  $mol_assert_equal(calls, 3);
7171
- $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
7172
- $mol_assert_not($mol_range2(i => i).every(v => v < 5));
7179
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
7180
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
7173
7181
  },
7174
7182
  'lazyfy'() {
7175
7183
  let calls = 0;
7176
- const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
7177
- $mol_assert_ok(list instanceof Array);
7184
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
7185
+ $mol_assert_equal(true, list instanceof Array);
7178
7186
  $mol_assert_equal(list.length, 4);
7179
7187
  $mol_assert_equal(calls, 0);
7180
7188
  $mol_assert_equal(list[0], 12);