mol_tree2 1.0.567 → 1.0.568

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
@@ -1978,7 +1978,12 @@ var $;
1978
1978
  var $;
1979
1979
  (function ($) {
1980
1980
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
1981
- return new Proxy(new $mol_range2_array(), {
1981
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
1982
+ if (typeof item !== 'function') {
1983
+ item = index => source[index];
1984
+ size = () => source.length;
1985
+ }
1986
+ return new Proxy(source, {
1982
1987
  get(target, field) {
1983
1988
  if (typeof field === 'string') {
1984
1989
  if (field === 'length')
@@ -1991,7 +1996,7 @@ var $;
1991
1996
  if (index === Math.trunc(index))
1992
1997
  return item(index);
1993
1998
  }
1994
- return target[field];
1999
+ return $mol_range2_array.prototype[field];
1995
2000
  },
1996
2001
  set(target, field) {
1997
2002
  return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
@@ -2032,13 +2037,16 @@ var $;
2032
2037
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
2033
2038
  }
2034
2039
  filter(check, context) {
2035
- const filtered = new $mol_range2_array();
2036
- for (let index = 0; index < this.length; ++index) {
2037
- const item = this[index];
2038
- if (check.call(context, item, index, this))
2039
- filtered.push(item);
2040
- }
2041
- return filtered;
2040
+ const filtered = [];
2041
+ let cursor = -1;
2042
+ return $mol_range2(index => {
2043
+ while (cursor < this.length && index >= filtered.length - 1) {
2044
+ const val = this[++cursor];
2045
+ if (check(val, cursor, this))
2046
+ filtered.push(val);
2047
+ }
2048
+ return filtered[index];
2049
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
2042
2050
  }
2043
2051
  forEach(proceed, context) {
2044
2052
  for (let [key, value] of this.entries())
@@ -2098,7 +2106,7 @@ var $;
2098
2106
  'lazy calls'() {
2099
2107
  let calls = 0;
2100
2108
  const list = $mol_range2(index => (++calls, index), () => 10);
2101
- $mol_assert_ok(list instanceof Array);
2109
+ $mol_assert_equal(true, list instanceof Array);
2102
2110
  $mol_assert_equal(list.length, 10);
2103
2111
  $mol_assert_equal(list[-1], undefined);
2104
2112
  $mol_assert_equal(list[0], 0);
@@ -2141,11 +2149,17 @@ var $;
2141
2149
  $mol_range2(i => i, () => 5).forEach(i => log += i);
2142
2150
  $mol_assert_equal(log, '01234');
2143
2151
  },
2152
+ 'reduce'() {
2153
+ let calls = 0;
2154
+ const list = $mol_range2().slice(1, 6);
2155
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
2156
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
2157
+ },
2144
2158
  'lazy concat'() {
2145
2159
  let calls1 = 0;
2146
2160
  let calls2 = 0;
2147
2161
  const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
2148
- $mol_assert_ok(list instanceof Array);
2162
+ $mol_assert_equal(true, list instanceof Array);
2149
2163
  $mol_assert_equal(list.length, 15);
2150
2164
  $mol_assert_equal(list[0], 0);
2151
2165
  $mol_assert_equal(list[4], 4);
@@ -2157,32 +2171,26 @@ var $;
2157
2171
  $mol_assert_equal(calls1, 2);
2158
2172
  $mol_assert_equal(calls2, 2);
2159
2173
  },
2160
- 'filter'() {
2174
+ 'lazy filter'() {
2161
2175
  let calls = 0;
2162
- const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
2163
- $mol_assert_ok(list instanceof Array);
2176
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
2177
+ $mol_assert_equal(true, list instanceof Array);
2164
2178
  $mol_assert_equal(list.length, 3);
2165
2179
  $mol_assert_equal(list[0], 1);
2166
2180
  $mol_assert_equal(list[2], 5);
2167
2181
  $mol_assert_equal(list[3], undefined);
2168
- $mol_assert_equal(calls, 10);
2182
+ $mol_assert_equal(calls, 8);
2169
2183
  },
2170
- 'reverse'() {
2184
+ 'lazy reverse'() {
2171
2185
  let calls = 0;
2172
2186
  const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
2173
- $mol_assert_ok(list instanceof Array);
2187
+ $mol_assert_equal(true, list instanceof Array);
2174
2188
  $mol_assert_equal(list.length, 3);
2175
2189
  $mol_assert_equal(list[0], 9);
2176
2190
  $mol_assert_equal(list[2], 7);
2177
2191
  $mol_assert_equal(list[3], undefined);
2178
2192
  $mol_assert_equal(calls, 2);
2179
2193
  },
2180
- 'reduce'() {
2181
- let calls = 0;
2182
- const list = $mol_range2().slice(1, 6);
2183
- $mol_assert_equal(list.reduce((s, v) => s + v), 15);
2184
- $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
2185
- },
2186
2194
  'lazy map'() {
2187
2195
  let calls1 = 0;
2188
2196
  let calls2 = 0;
@@ -2192,7 +2200,7 @@ var $;
2192
2200
  $mol_assert_equal(source, self);
2193
2201
  return index + 10;
2194
2202
  }, () => 5);
2195
- $mol_assert_ok(target instanceof Array);
2203
+ $mol_assert_equal(true, target instanceof Array);
2196
2204
  $mol_assert_equal(target.length, 5);
2197
2205
  $mol_assert_equal(target[0], 10);
2198
2206
  $mol_assert_equal(target[4], 14);
@@ -2203,7 +2211,7 @@ var $;
2203
2211
  'lazy slice'() {
2204
2212
  let calls = 0;
2205
2213
  const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
2206
- $mol_assert_ok(list instanceof Array);
2214
+ $mol_assert_equal(true, list instanceof Array);
2207
2215
  $mol_assert_equal(list.length, 4);
2208
2216
  $mol_assert_equal(list[0], 3);
2209
2217
  $mol_assert_equal(list[3], 6);
@@ -2212,22 +2220,22 @@ var $;
2212
2220
  },
2213
2221
  'lazy some'() {
2214
2222
  let calls = 0;
2215
- $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
2223
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
2216
2224
  $mol_assert_equal(calls, 3);
2217
- $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
2218
- $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
2225
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
2226
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
2219
2227
  },
2220
2228
  'lazy every'() {
2221
2229
  let calls = 0;
2222
- $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
2230
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
2223
2231
  $mol_assert_equal(calls, 3);
2224
- $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
2225
- $mol_assert_not($mol_range2(i => i).every(v => v < 5));
2232
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
2233
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
2226
2234
  },
2227
2235
  'lazyfy'() {
2228
2236
  let calls = 0;
2229
- const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
2230
- $mol_assert_ok(list instanceof Array);
2237
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
2238
+ $mol_assert_equal(true, list instanceof Array);
2231
2239
  $mol_assert_equal(list.length, 4);
2232
2240
  $mol_assert_equal(calls, 0);
2233
2241
  $mol_assert_equal(list[0], 12);