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 Sep 23, 2023
1 parent 7390ac7 commit 736532f
Show file tree
Hide file tree
Showing 10 changed files with 572 additions and 14 deletions.
4 changes: 2 additions & 2 deletions node.js

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

2 changes: 1 addition & 1 deletion node.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,8 @@ var $;
result = compare_pojo(left, right);
else if (!Reflect.getPrototypeOf(left_proto))
result = compare_pojo(left, right);
else if (Symbol.toPrimitive in left)
result = compare_primitive(left, right);
else if (Array.isArray(left))
result = compare_array(left, right);
else if (left instanceof Set)
Expand All @@ -963,8 +965,6 @@ var $;
result = compare_buffer(left, right);
else if (Symbol.iterator in left)
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
else if (Symbol.toPrimitive in left)
result = compare_primitive(left, right);
else
result = false;
}
Expand Down
283 changes: 281 additions & 2 deletions node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,8 @@ var $;
result = compare_pojo(left, right);
else if (!Reflect.getPrototypeOf(left_proto))
result = compare_pojo(left, right);
else if (Symbol.toPrimitive in left)
result = compare_primitive(left, right);
else if (Array.isArray(left))
result = compare_array(left, right);
else if (left instanceof Set)
Expand All @@ -955,8 +957,6 @@ var $;
result = compare_buffer(left, right);
else if (Symbol.iterator in left)
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
else if (Symbol.toPrimitive in left)
result = compare_primitive(left, right);
else
result = false;
}
Expand Down Expand Up @@ -12378,6 +12378,283 @@ var $;
;
"use strict";
var $;
(function ($) {
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
return new Proxy(new $mol_range2_array(), {
get(target, field) {
if (typeof field === 'string') {
if (field === 'length')
return size();
const index = Number(field);
if (index < 0)
return undefined;
if (index >= size())
return undefined;
if (index === Math.trunc(index))
return item(index);
}
return target[field];
},
set(target, field) {
return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
},
ownKeys(target) {
return [...Array(size())].map((v, i) => String(i)).concat('length');
},
getOwnPropertyDescriptor(target, field) {
if (field === "length")
return {
value: size(),
writable: true,
enumerable: false,
configurable: false,
};
const index = Number(field);
if (index === Math.trunc(index))
return {
get: () => this.get(target, field, this),
enumerable: true,
configurable: true,
};
return Object.getOwnPropertyDescriptor(target, field);
}
});
}
$.$mol_range2 = $mol_range2;
class $mol_range2_array extends Array {
concat(...tail) {
if (tail.length === 0)
return this;
if (tail.length > 1) {
let list = this;
for (let item of tail)
list = list.concat(item);
return list;
}
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;
}
forEach(proceed, context) {
for (let [key, value] of this.entries())
proceed.call(context, value, key, this);
}
map(proceed, context) {
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
}
reduce(merge, result) {
let index = 0;
if (arguments.length === 1) {
result = this[index++];
}
for (; index < this.length; ++index) {
result = merge(result, this[index], index, this);
}
return result;
}
toReversed() {
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
}
slice(from = 0, to = this.length) {
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
}
some(check, context) {
for (let index = 0; index < this.length; ++index) {
if (check.call(context, this[index], index, this))
return true;
}
return false;
}
every(check, context) {
for (let index = 0; index < this.length; ++index) {
if (!check.call(context, this[index], index, this))
return false;
}
return true;
}
reverse() {
return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
}
sort() {
return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
}
[Symbol.toPrimitive]() {
return $mol_guid();
}
}
$.$mol_range2_array = $mol_range2_array;
})($ || ($ = {}));
//mol/range2/range2.ts
;
"use strict";
var $;
(function ($) {
$mol_test({
'lazy calls'() {
let calls = 0;
const list = $mol_range2(index => (++calls, index), () => 10);
$mol_assert_ok(list instanceof Array);
$mol_assert_equal(list.length, 10);
$mol_assert_equal(list[-1], undefined);
$mol_assert_equal(list[0], 0);
$mol_assert_equal(list[9], 9);
$mol_assert_equal(list[9.5], undefined);
$mol_assert_equal(list[10], undefined);
$mol_assert_equal(calls, 2);
},
'infinity list'() {
let calls = 0;
const list = $mol_range2(index => (++calls, index));
$mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
$mol_assert_equal(list[0], 0);
$mol_assert_equal(list[4], 4);
$mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
$mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
$mol_assert_equal(calls, 3);
},
'stringify'() {
const list = $mol_range2(i => i, () => 5);
$mol_assert_equal(list.toString(), '0,1,2,3,4');
$mol_assert_equal(list.join(';'), '0;1;2;3;4');
},
'for-of'() {
let log = '';
for (let i of $mol_range2(i => i + 1, () => 5)) {
log += i;
}
$mol_assert_equal(log, '12345');
},
'for-in'() {
let log = '';
for (let i in $mol_range2(i => i, () => 5)) {
log += i;
}
$mol_assert_equal(log, '01234');
},
'forEach'() {
let log = '';
$mol_range2(i => i, () => 5).forEach(i => log += i);
$mol_assert_equal(log, '01234');
},
'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(list.length, 15);
$mol_assert_equal(list[0], 0);
$mol_assert_equal(list[4], 4);
$mol_assert_equal(list[5], 0);
$mol_assert_equal(list[9], 4);
$mol_assert_equal(list[10], 0);
$mol_assert_equal(list[14], 4);
$mol_assert_equal(list[15], undefined);
$mol_assert_equal(calls1, 2);
$mol_assert_equal(calls2, 2);
},
'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);
$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);
},
'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(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;
const source = $mol_range2(index => (++calls1, index), () => 5);
const target = source.map((item, index, self) => {
++calls2;
$mol_assert_equal(source, self);
return index + 10;
}, () => 5);
$mol_assert_ok(target instanceof Array);
$mol_assert_equal(target.length, 5);
$mol_assert_equal(target[0], 10);
$mol_assert_equal(target[4], 14);
$mol_assert_equal(target[5], undefined);
$mol_assert_equal(calls1, 2);
$mol_assert_equal(calls2, 2);
},
'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(list.length, 4);
$mol_assert_equal(list[0], 3);
$mol_assert_equal(list[3], 6);
$mol_assert_equal(list[4], undefined);
$mol_assert_equal(calls, 2);
},
'lazy some'() {
let calls = 0;
$mol_assert_ok($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));
},
'lazy every'() {
let calls = 0;
$mol_assert_not($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));
},
'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);
$mol_assert_equal(list.length, 4);
$mol_assert_equal(calls, 0);
$mol_assert_equal(list[0], 12);
$mol_assert_equal(list[3], 15);
$mol_assert_equal(list[4], undefined);
$mol_assert_equal(calls, 2);
},
'prevent modification'() {
const list = $mol_range2(i => i, () => 5);
$mol_assert_fail(() => list.push(4), TypeError);
$mol_assert_fail(() => list.pop(), TypeError);
$mol_assert_fail(() => list.unshift(4), TypeError);
$mol_assert_fail(() => list.shift(), TypeError);
$mol_assert_fail(() => list.splice(1, 2), TypeError);
$mol_assert_fail(() => list[1] = 2, TypeError);
$mol_assert_fail(() => list.reverse(), TypeError);
$mol_assert_fail(() => list.sort(), TypeError);
$mol_assert_equal(list.toString(), '0,1,2,3,4');
}
});
})($ || ($ = {}));
//mol/range2/range2.test.ts
;
"use strict";
var $;
(function ($) {
$mol_test({
'nulls & undefineds'() {
Expand Down Expand Up @@ -12407,6 +12684,8 @@ var $;
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
$mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
$mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
},
'Non POJO are different'() {
class Thing extends Object {
Expand Down
2 changes: 1 addition & 1 deletion node.test.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions web.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.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions web.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,8 @@ var $;
result = compare_pojo(left, right);
else if (!Reflect.getPrototypeOf(left_proto))
result = compare_pojo(left, right);
else if (Symbol.toPrimitive in left)
result = compare_primitive(left, right);
else if (Array.isArray(left))
result = compare_array(left, right);
else if (left instanceof Set)
Expand All @@ -954,8 +956,6 @@ var $;
result = compare_buffer(left, right);
else if (Symbol.iterator in left)
result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
else if (Symbol.toPrimitive in left)
result = compare_primitive(left, right);
else
result = false;
}
Expand Down
Loading

0 comments on commit 736532f

Please sign in to comment.