Skip to content

Commit

Permalink
Deploying to gh-pages from @ b9e61e4 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelZubkov committed Jan 18, 2024
1 parent 8035fa6 commit c78fdb4
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 68 deletions.
74 changes: 41 additions & 33 deletions node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12621,7 +12621,12 @@ var $;
var $;
(function ($) {
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
return new Proxy(new $mol_range2_array(), {
const source = typeof item === 'function' ? new $mol_range2_array() : item;
if (typeof item !== 'function') {
item = index => source[index];
size = () => source.length;
}
return new Proxy(source, {
get(target, field) {
if (typeof field === 'string') {
if (field === 'length')
Expand All @@ -12634,7 +12639,7 @@ var $;
if (index === Math.trunc(index))
return item(index);
}
return target[field];
return $mol_range2_array.prototype[field];
},
set(target, field) {
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
Expand Down Expand Up @@ -12675,13 +12680,16 @@ var $;
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
}
filter(check, context) {
const filtered = new $mol_range2_array();
for (let index = 0; index < this.length; ++index) {
const item = this[index];
if (check.call(context, item, index, this))
filtered.push(item);
}
return filtered;
const filtered = [];
let cursor = -1;
return $mol_range2(index => {
while (cursor < this.length && index >= filtered.length - 1) {
const val = this[++cursor];
if (check(val, cursor, this))
filtered.push(val);
}
return filtered[index];
}, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
}
forEach(proceed, context) {
for (let [key, value] of this.entries())
Expand Down Expand Up @@ -12741,7 +12749,7 @@ var $;
'lazy calls'() {
let calls = 0;
const list = $mol_range2(index => (++calls, index), () => 10);
$mol_assert_ok(list instanceof Array);
$mol_assert_equal(true, list instanceof Array);
$mol_assert_equal(list.length, 10);
$mol_assert_equal(list[-1], undefined);
$mol_assert_equal(list[0], 0);
Expand Down Expand Up @@ -12784,11 +12792,17 @@ var $;
$mol_range2(i => i, () => 5).forEach(i => log += i);
$mol_assert_equal(log, '01234');
},
'reduce'() {
let calls = 0;
const list = $mol_range2().slice(1, 6);
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
},
'lazy concat'() {
let calls1 = 0;
let calls2 = 0;
const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
$mol_assert_ok(list instanceof Array);
$mol_assert_equal(true, list instanceof Array);
$mol_assert_equal(list.length, 15);
$mol_assert_equal(list[0], 0);
$mol_assert_equal(list[4], 4);
Expand All @@ -12800,32 +12814,26 @@ var $;
$mol_assert_equal(calls1, 2);
$mol_assert_equal(calls2, 2);
},
'filter'() {
'lazy filter'() {
let calls = 0;
const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
$mol_assert_ok(list instanceof Array);
const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
$mol_assert_equal(true, list instanceof Array);
$mol_assert_equal(list.length, 3);
$mol_assert_equal(list[0], 1);
$mol_assert_equal(list[2], 5);
$mol_assert_equal(list[3], undefined);
$mol_assert_equal(calls, 10);
$mol_assert_equal(calls, 8);
},
'reverse'() {
'lazy reverse'() {
let calls = 0;
const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
$mol_assert_ok(list instanceof Array);
$mol_assert_equal(true, list instanceof Array);
$mol_assert_equal(list.length, 3);
$mol_assert_equal(list[0], 9);
$mol_assert_equal(list[2], 7);
$mol_assert_equal(list[3], undefined);
$mol_assert_equal(calls, 2);
},
'reduce'() {
let calls = 0;
const list = $mol_range2().slice(1, 6);
$mol_assert_equal(list.reduce((s, v) => s + v), 15);
$mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
},
'lazy map'() {
let calls1 = 0;
let calls2 = 0;
Expand All @@ -12835,7 +12843,7 @@ var $;
$mol_assert_equal(source, self);
return index + 10;
}, () => 5);
$mol_assert_ok(target instanceof Array);
$mol_assert_equal(true, target instanceof Array);
$mol_assert_equal(target.length, 5);
$mol_assert_equal(target[0], 10);
$mol_assert_equal(target[4], 14);
Expand All @@ -12846,7 +12854,7 @@ var $;
'lazy slice'() {
let calls = 0;
const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
$mol_assert_ok(list instanceof Array);
$mol_assert_equal(true, list instanceof Array);
$mol_assert_equal(list.length, 4);
$mol_assert_equal(list[0], 3);
$mol_assert_equal(list[3], 6);
Expand All @@ -12855,22 +12863,22 @@ var $;
},
'lazy some'() {
let calls = 0;
$mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
$mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
$mol_assert_equal(calls, 3);
$mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
$mol_assert_ok($mol_range2(i => i).some(v => v > 5));
$mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
$mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
},
'lazy every'() {
let calls = 0;
$mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
$mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
$mol_assert_equal(calls, 3);
$mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
$mol_assert_not($mol_range2(i => i).every(v => v < 5));
$mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
$mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
},
'lazyfy'() {
let calls = 0;
const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
$mol_assert_ok(list instanceof Array);
const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
$mol_assert_equal(true, list instanceof Array);
$mol_assert_equal(list.length, 4);
$mol_assert_equal(calls, 0);
$mol_assert_equal(list[0], 12);
Expand Down
2 changes: 1 addition & 1 deletion node.test.js.map

Large diffs are not rendered by default.

74 changes: 41 additions & 33 deletions web.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web.test.js.map

Large diffs are not rendered by default.

0 comments on commit c78fdb4

Please sign in to comment.