functionalscript 0.3.7 → 0.3.9
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/com/cpp/module.f.js +0 -1
- package/com/cs/module.f.js +5 -6
- package/com/rust/module.f.d.ts +3 -3
- package/com/rust/module.f.js +24 -29
- package/com/test/build.f.js +2 -2
- package/com/types/module.f.d.ts +1 -1
- package/com/types/module.f.js +1 -2
- package/com/types/testlib.f.js +0 -1
- package/commonjs/build/module.f.d.ts +2 -2
- package/commonjs/build/module.f.js +3 -6
- package/commonjs/build/test.f.js +0 -4
- package/commonjs/module/function/module.f.d.ts +1 -1
- package/commonjs/module/function/module.f.js +1 -1
- package/commonjs/module/module.f.d.ts +1 -1
- package/commonjs/module/module.f.js +2 -3
- package/commonjs/path/module.f.d.ts +5 -5
- package/commonjs/path/module.f.js +6 -8
- package/commonjs/path/test.f.js +1 -2
- package/crypto/prime_field/module.f.d.ts +1 -1
- package/crypto/prime_field/module.f.js +1 -1
- package/crypto/secp/module.f.d.ts +1 -1
- package/crypto/secp/module.f.js +2 -2
- package/crypto/sha2/module.f.d.ts +75 -12
- package/crypto/sha2/module.f.js +246 -139
- package/crypto/sha2/test.f.d.ts +22 -3
- package/crypto/sha2/test.f.js +120 -67
- package/dev/test/module.f.d.ts +1 -1
- package/dev/test/module.f.js +4 -5
- package/dev/test.f.js +0 -4
- package/djs/module.f.d.ts +1 -1
- package/djs/module.f.js +0 -1
- package/djs/parser/module.f.d.ts +1 -1
- package/djs/parser/module.f.js +0 -2
- package/djs/serializer/module.f.d.ts +2 -2
- package/djs/serializer/module.f.js +0 -2
- package/djs/tokenizer/module.f.js +0 -1
- package/fsc/test.f.js +0 -1
- package/js/tokenizer/module.f.d.ts +1 -1
- package/js/tokenizer/module.f.js +1 -1
- package/json/parser/module.f.d.ts +2 -2
- package/json/parser/module.f.js +0 -3
- package/json/serializer/module.f.js +0 -2
- package/json/tokenizer/module.f.js +0 -1
- package/package.json +1 -1
- package/text/ascii/module.f.d.ts +1 -1
- package/text/ascii/module.f.js +2 -3
- package/text/ascii/test.f.js +2 -4
- package/text/module.f.d.ts +18 -3
- package/text/module.f.js +22 -6
- package/text/sgr/module.f.js +1 -1
- package/text/test.f.d.ts +4 -1
- package/text/test.f.js +24 -16
- package/text/utf16/module.f.d.ts +5 -6
- package/text/utf16/module.f.js +9 -10
- package/text/utf16/test.f.js +29 -30
- package/text/utf8/module.f.d.ts +8 -5
- package/text/utf8/module.f.js +3 -5
- package/text/utf8/test.f.js +34 -35
- package/types/bigfloat/module.f.js +1 -1
- package/types/bigint/module.f.d.ts +36 -7
- package/types/bigint/module.f.js +40 -11
- package/types/bigint/test.f.d.ts +8 -0
- package/types/bigint/test.f.js +81 -2
- package/types/bit_vec/module.f.d.ts +103 -83
- package/types/bit_vec/module.f.js +68 -110
- package/types/bit_vec/test.f.d.ts +20 -8
- package/types/bit_vec/test.f.js +110 -117
- package/types/btree/find/module.f.d.ts +11 -10
- package/types/btree/find/module.f.js +1 -5
- package/types/btree/find/test.f.js +4 -6
- package/types/btree/module.f.d.ts +3 -3
- package/types/btree/module.f.js +2 -5
- package/types/btree/remove/module.f.d.ts +2 -2
- package/types/btree/remove/module.f.js +0 -3
- package/types/btree/remove/test.f.js +4 -7
- package/types/btree/set/module.f.d.ts +2 -2
- package/types/btree/set/module.f.js +2 -6
- package/types/btree/set/test.f.js +3 -6
- package/types/btree/test.f.js +9 -13
- package/types/btree/types/module.f.d.ts +1 -3
- package/types/byte_set/module.f.d.ts +3 -3
- package/types/byte_set/module.f.js +1 -4
- package/types/byte_set/test.f.js +2 -4
- package/types/function/compare/module.f.d.ts +1 -5
- package/types/function/compare/module.f.js +0 -1
- package/types/function/compare/test.f.js +1 -2
- package/types/function/module.f.d.ts +1 -1
- package/types/function/module.f.js +1 -1
- package/types/function/operator/module.f.d.ts +2 -3
- package/types/function/operator/module.f.js +5 -5
- package/types/function/test.f.js +1 -2
- package/types/list/module.f.d.ts +1 -1
- package/types/list/module.f.js +9 -9
- package/types/list/test.f.js +2 -4
- package/types/map/module.f.d.ts +7 -9
- package/types/map/module.f.js +6 -15
- package/types/map/test.f.js +3 -4
- package/types/nibble_set/module.f.d.ts +2 -3
- package/types/nibble_set/test.f.js +26 -27
- package/types/nullable/test.f.js +2 -2
- package/types/number/module.f.d.ts +2 -2
- package/types/number/module.f.js +1 -2
- package/types/number/test.f.js +1 -2
- package/types/object/module.f.d.ts +5 -5
- package/types/object/module.f.js +2 -4
- package/types/object/test.f.js +3 -3
- package/types/range/test.f.js +6 -6
- package/types/range_map/module.f.d.ts +8 -8
- package/types/range_map/module.f.js +3 -9
- package/types/range_map/test.f.js +2 -4
- package/types/result/module.f.d.ts +2 -3
- package/types/sorted_list/module.f.d.ts +8 -8
- package/types/sorted_list/module.f.js +2 -6
- package/types/sorted_list/test.f.js +12 -17
- package/types/sorted_set/module.f.d.ts +2 -2
- package/types/sorted_set/module.f.js +2 -5
- package/types/sorted_set/test.f.js +14 -19
- package/types/string/module.f.d.ts +5 -5
- package/types/string/module.f.js +2 -4
- package/types/string/test.f.js +2 -4
- package/types/string_set/module.f.d.ts +2 -2
- package/types/string_set/module.f.js +5 -11
- package/types/string_set/test.f.js +25 -25
package/types/list/module.f.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { identity, fn, compose } from "../function/module.f.js";
|
|
2
2
|
import { addition, logicalNot, strictEqual, stateScanToScan, foldToScan, reduceToScan, } from "../function/operator/module.f.js";
|
|
3
|
-
const fromArray = array => {
|
|
4
|
-
const at = i => i < array.length ? { first: array[i], tail: () => at(i + 1) } : null;
|
|
3
|
+
const fromArray = (array) => {
|
|
4
|
+
const at = (i) => i < array.length ? { first: array[i], tail: () => at(i + 1) } : null;
|
|
5
5
|
return at(0);
|
|
6
6
|
};
|
|
7
|
-
export const concat = head => tail => tail === null ? head : ({ head, tail });
|
|
8
|
-
const trampoline = list => {
|
|
7
|
+
export const concat = (head) => (tail) => tail === null ? head : ({ head, tail });
|
|
8
|
+
const trampoline = (list) => {
|
|
9
9
|
while (typeof list === 'function') {
|
|
10
10
|
list = list();
|
|
11
11
|
}
|
|
12
12
|
return list;
|
|
13
13
|
};
|
|
14
|
-
export const next = head => {
|
|
14
|
+
export const next = (head) => {
|
|
15
15
|
let tail = null;
|
|
16
16
|
while (true) {
|
|
17
17
|
head = trampoline(head);
|
|
@@ -31,7 +31,7 @@ export const next = head => {
|
|
|
31
31
|
[head, tail] = [tail, null];
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
export const iterable = list => ({
|
|
34
|
+
export const iterable = (list) => ({
|
|
35
35
|
*[Symbol.iterator]() {
|
|
36
36
|
let i = list;
|
|
37
37
|
while (true) {
|
|
@@ -45,11 +45,11 @@ export const iterable = list => ({
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
const { from } = Array;
|
|
48
|
-
export const toArray = list => {
|
|
48
|
+
export const toArray = (list) => {
|
|
49
49
|
const u = trampoline(list);
|
|
50
50
|
return u instanceof Array ? u : from(iterable(u));
|
|
51
51
|
};
|
|
52
|
-
const apply = f => input => () => {
|
|
52
|
+
const apply = (f) => (input) => () => {
|
|
53
53
|
const n = next(input);
|
|
54
54
|
if (n === null) {
|
|
55
55
|
return null;
|
|
@@ -58,7 +58,7 @@ const apply = f => input => () => {
|
|
|
58
58
|
};
|
|
59
59
|
const flatStep = ({ first, tail }) => concat(first)(flat(tail));
|
|
60
60
|
export const flat = apply(flatStep);
|
|
61
|
-
const mapStep = f => ({ first, tail }) => ({ first: f(first), tail: map(f)(tail) });
|
|
61
|
+
const mapStep = (f) => ({ first, tail }) => ({ first: f(first), tail: map(f)(tail) });
|
|
62
62
|
export const map = f => apply(mapStep(f));
|
|
63
63
|
export const flatMap = f => compose(map(f))(flat);
|
|
64
64
|
const filterStep = f => ({ first, tail }) => {
|
package/types/list/test.f.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import * as _ from "./module.f.js";
|
|
2
2
|
import * as json from "../../json/module.f.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import * as operator from "../function/operator/module.f.js";
|
|
6
|
-
const { addition, strictEqual, reduceToScan } = operator;
|
|
3
|
+
import { sort } from "../object/module.f.js";
|
|
4
|
+
import { addition, strictEqual, reduceToScan } from "../function/operator/module.f.js";
|
|
7
5
|
const stringify = sequence => json.stringify(sort)(_.toArray(sequence));
|
|
8
6
|
const stringifyTest = () => {
|
|
9
7
|
const s = stringify([1, 2, 3]);
|
package/types/map/module.f.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as Operator from '../function/operator/module.f.ts';
|
|
5
|
-
export type Sign = Compare.Sign;
|
|
1
|
+
import type { Tree } from '../btree/types/module.f.ts';
|
|
2
|
+
import { type List } from '../list/module.f.ts';
|
|
3
|
+
import type { Reduce } from '../function/operator/module.f.ts';
|
|
6
4
|
export type Entry<T> = readonly [string, T];
|
|
7
|
-
export type Map<T> =
|
|
5
|
+
export type Map<T> = Tree<Entry<T>>;
|
|
8
6
|
export declare const at: (name: string) => <T>(map: Map<T>) => T | null;
|
|
9
|
-
export declare const setReduce: <T>(reduce:
|
|
7
|
+
export declare const setReduce: <T>(reduce: Reduce<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>;
|
|
10
8
|
export declare const setReplace: (name: string) => <T>(value: T) => (map: Map<T>) => Map<T>;
|
|
11
|
-
export declare const entries: <T>(map: Map<T>) =>
|
|
12
|
-
export declare const fromEntries: <T>(entries:
|
|
9
|
+
export declare const entries: <T>(map: Map<T>) => List<Entry<T>>;
|
|
10
|
+
export declare const fromEntries: <T>(entries: List<Entry<T>>) => Map<T>;
|
|
13
11
|
export declare const remove: (name: string) => <T>(map: Map<T>) => Map<T>;
|
|
14
12
|
export declare const empty: null;
|
package/types/map/module.f.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
const { remove: btreeRemove } = btr;
|
|
8
|
-
import * as bt from "../btree/module.f.js";
|
|
9
|
-
const { values } = bt;
|
|
10
|
-
import * as Compare from "../function/compare/module.f.js";
|
|
11
|
-
import * as s from "../string/module.f.js";
|
|
12
|
-
const { cmp } = s;
|
|
13
|
-
import * as list from "../list/module.f.js";
|
|
14
|
-
const { fold } = list;
|
|
15
|
-
import * as Operator from "../function/operator/module.f.js";
|
|
1
|
+
import { value, find } from "../btree/find/module.f.js";
|
|
2
|
+
import { set } from "../btree/set/module.f.js";
|
|
3
|
+
import { remove as btreeRemove } from "../btree/remove/module.f.js";
|
|
4
|
+
import { values } from "../btree/module.f.js";
|
|
5
|
+
import { cmp } from "../string/module.f.js";
|
|
6
|
+
import { fold } from "../list/module.f.js";
|
|
16
7
|
const keyCmp = a => ([b]) => cmp(a)(b);
|
|
17
8
|
export const at = (name) => (map) => {
|
|
18
9
|
if (map === null) {
|
package/types/map/test.f.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import * as seq from "../list/module.f.js";
|
|
1
|
+
import { at, setReplace, setReduce, empty, entries, remove } from "./module.f.js";
|
|
2
|
+
import { toArray } from "../list/module.f.js";
|
|
4
3
|
export default {
|
|
5
4
|
main: [
|
|
6
5
|
() => {
|
|
@@ -91,7 +90,7 @@ export default {
|
|
|
91
90
|
if (at('a')(m) !== null) {
|
|
92
91
|
throw 'error';
|
|
93
92
|
}
|
|
94
|
-
const e =
|
|
93
|
+
const e = toArray(entries(m));
|
|
95
94
|
if (e.length !== 2) {
|
|
96
95
|
throw 'error';
|
|
97
96
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
type NibbleSet = number;
|
|
2
|
-
type Nibble = number;
|
|
1
|
+
export type NibbleSet = number;
|
|
2
|
+
export type Nibble = number;
|
|
3
3
|
export declare const empty = 0;
|
|
4
4
|
export declare const universe = 65535;
|
|
5
5
|
export declare const has: (n: Nibble) => (s: NibbleSet) => boolean;
|
|
@@ -7,4 +7,3 @@ export declare const set: (n: Nibble) => (s: NibbleSet) => NibbleSet;
|
|
|
7
7
|
export declare const complement: (n: NibbleSet) => NibbleSet;
|
|
8
8
|
export declare const unset: (n: Nibble) => (s: NibbleSet) => NibbleSet;
|
|
9
9
|
export declare const setRange: (r: readonly [number, number]) => (s: NibbleSet) => NibbleSet;
|
|
10
|
-
export {};
|
|
@@ -1,88 +1,87 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import * as _ from "./module.f.js";
|
|
1
|
+
import { every, map, countdown } from "../list/module.f.js";
|
|
2
|
+
import { empty, has, set, setRange, unset, universe, complement } from "./module.f.js";
|
|
4
3
|
export default {
|
|
5
4
|
has: () => {
|
|
6
|
-
if (
|
|
7
|
-
throw
|
|
5
|
+
if (has(0)(empty)) {
|
|
6
|
+
throw empty;
|
|
8
7
|
}
|
|
9
|
-
if (
|
|
10
|
-
throw
|
|
8
|
+
if (has(1)(empty)) {
|
|
9
|
+
throw empty;
|
|
11
10
|
}
|
|
12
|
-
if (
|
|
13
|
-
throw
|
|
11
|
+
if (has(15)(empty)) {
|
|
12
|
+
throw empty;
|
|
14
13
|
}
|
|
15
14
|
},
|
|
16
15
|
set: [
|
|
17
16
|
() => {
|
|
18
|
-
const s =
|
|
17
|
+
const s = set(0)(empty);
|
|
19
18
|
if (s !== 1) {
|
|
20
19
|
throw s;
|
|
21
20
|
}
|
|
22
|
-
if (!
|
|
21
|
+
if (!has(0)(s)) {
|
|
23
22
|
throw s;
|
|
24
23
|
}
|
|
25
|
-
if (
|
|
24
|
+
if (has(1)(s)) {
|
|
26
25
|
throw s;
|
|
27
26
|
}
|
|
28
|
-
if (
|
|
27
|
+
if (has(15)(s)) {
|
|
29
28
|
throw s;
|
|
30
29
|
}
|
|
31
30
|
},
|
|
32
31
|
() => {
|
|
33
|
-
const s =
|
|
32
|
+
const s = set(15)(empty);
|
|
34
33
|
if (s !== 0x8000) {
|
|
35
34
|
throw s;
|
|
36
35
|
}
|
|
37
|
-
if (
|
|
36
|
+
if (has(0)(s)) {
|
|
38
37
|
throw s;
|
|
39
38
|
}
|
|
40
|
-
if (
|
|
39
|
+
if (has(1)(s)) {
|
|
41
40
|
throw s;
|
|
42
41
|
}
|
|
43
|
-
if (!
|
|
42
|
+
if (!has(15)(s)) {
|
|
44
43
|
throw s;
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
],
|
|
48
47
|
unset: () => [
|
|
49
48
|
() => {
|
|
50
|
-
const a =
|
|
51
|
-
const result =
|
|
49
|
+
const a = set(0)(empty);
|
|
50
|
+
const result = unset(0)(a);
|
|
52
51
|
if (result !== 0) {
|
|
53
52
|
throw result;
|
|
54
53
|
}
|
|
55
54
|
},
|
|
56
55
|
() => {
|
|
57
|
-
const a =
|
|
58
|
-
const result =
|
|
56
|
+
const a = set(15)(empty);
|
|
57
|
+
const result = unset(15)(a);
|
|
59
58
|
if (result !== 0) {
|
|
60
59
|
throw result;
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
62
|
],
|
|
64
63
|
setRange: () => {
|
|
65
|
-
const result =
|
|
64
|
+
const result = setRange([2, 5])(empty);
|
|
66
65
|
if (result !== 60) {
|
|
67
66
|
throw result;
|
|
68
67
|
}
|
|
69
68
|
},
|
|
70
69
|
universe: () => {
|
|
71
|
-
const x = every(map((v) =>
|
|
70
|
+
const x = every(map((v) => has(v)(universe))(countdown(16)));
|
|
72
71
|
if (!x) {
|
|
73
72
|
throw x;
|
|
74
73
|
}
|
|
75
74
|
},
|
|
76
75
|
compliment: {
|
|
77
76
|
empty: () => {
|
|
78
|
-
const r =
|
|
79
|
-
if (r !==
|
|
77
|
+
const r = complement(empty);
|
|
78
|
+
if (r !== universe) {
|
|
80
79
|
throw r;
|
|
81
80
|
}
|
|
82
81
|
},
|
|
83
82
|
universe: () => {
|
|
84
|
-
const r =
|
|
85
|
-
if (r !==
|
|
83
|
+
const r = complement(universe);
|
|
84
|
+
if (r !== empty) {
|
|
86
85
|
throw r;
|
|
87
86
|
}
|
|
88
87
|
},
|
package/types/nullable/test.f.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type List } from '../list/module.f.ts';
|
|
2
|
-
import
|
|
2
|
+
import { type Sign } from '../function/compare/module.f.ts';
|
|
3
3
|
export declare const sum: (input: List<number>) => number;
|
|
4
4
|
export declare const min: (input: List<number>) => number | null;
|
|
5
5
|
export declare const max: (input: List<number>) => number | null;
|
|
6
|
-
export declare const cmp: (a: number) => (b: number) =>
|
|
6
|
+
export declare const cmp: (a: number) => (b: number) => Sign;
|
package/types/number/module.f.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { reduce } from "../list/module.f.js";
|
|
2
2
|
import { addition, min as minOp, max as maxOp } from "../function/operator/module.f.js";
|
|
3
|
-
import
|
|
4
|
-
const { unsafeCmp } = compare;
|
|
3
|
+
import { unsafeCmp } from "../function/compare/module.f.js";
|
|
5
4
|
export const sum = reduce(addition)(0);
|
|
6
5
|
export const min = reduce(minOp)(null);
|
|
7
6
|
export const max = reduce(maxOp)(null);
|
package/types/number/test.f.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { type List } from '../list/module.f.ts';
|
|
2
|
+
import { type Map as BtMap } from '../map/module.f.ts';
|
|
3
3
|
export type Map<T> = {
|
|
4
4
|
readonly [k in string]: T;
|
|
5
5
|
};
|
|
6
6
|
export type Entry<T> = readonly [string, T];
|
|
7
7
|
export declare const at: (name: string) => <T>(object: Map<T>) => T | null;
|
|
8
|
-
export declare const sort: <T>(e:
|
|
9
|
-
export declare const fromEntries: <T>(e:
|
|
10
|
-
export declare const fromMap: <T>(m:
|
|
8
|
+
export declare const sort: <T>(e: List<Entry<T>>) => List<Entry<T>>;
|
|
9
|
+
export declare const fromEntries: <T>(e: List<Entry<T>>) => Map<T>;
|
|
10
|
+
export declare const fromMap: <T>(m: BtMap<T>) => Map<T>;
|
package/types/object/module.f.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import * as btMap from "../map/module.f.js";
|
|
4
|
-
const { entries: mapEntries, fromEntries: mapFromEntries } = btMap;
|
|
1
|
+
import { iterable } from "../list/module.f.js";
|
|
2
|
+
import { entries as mapEntries, fromEntries as mapFromEntries } from "../map/module.f.js";
|
|
5
3
|
const { getOwnPropertyDescriptor, fromEntries: objectFromEntries } = Object;
|
|
6
4
|
export const at = name => object => {
|
|
7
5
|
const r = getOwnPropertyDescriptor(object, name);
|
package/types/object/test.f.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { at } from "./module.f.js";
|
|
2
2
|
export default {
|
|
3
3
|
ctor: () => {
|
|
4
4
|
const a = {};
|
|
5
|
-
const value =
|
|
5
|
+
const value = at('constructor')(a);
|
|
6
6
|
if (value !== null) {
|
|
7
7
|
throw value;
|
|
8
8
|
}
|
|
9
9
|
},
|
|
10
10
|
property: () => {
|
|
11
11
|
const a = { constructor: 42 };
|
|
12
|
-
const value =
|
|
12
|
+
const value = at('constructor')(a);
|
|
13
13
|
if (value !== 42) {
|
|
14
14
|
throw value;
|
|
15
15
|
}
|
package/types/range/test.f.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { contains } from "./module.f.js";
|
|
2
2
|
export default () => {
|
|
3
|
-
if (!
|
|
3
|
+
if (!contains([0, 5])(1)) {
|
|
4
4
|
throw 1;
|
|
5
5
|
}
|
|
6
|
-
if (!
|
|
6
|
+
if (!contains([0, 5])(0)) {
|
|
7
7
|
throw 0;
|
|
8
8
|
}
|
|
9
|
-
if (!
|
|
9
|
+
if (!contains([0, 5])(5)) {
|
|
10
10
|
throw 5;
|
|
11
11
|
}
|
|
12
|
-
if (
|
|
12
|
+
if (contains([0, 5])(-1)) {
|
|
13
13
|
throw -1;
|
|
14
14
|
}
|
|
15
|
-
if (
|
|
15
|
+
if (contains([0, 5])(6)) {
|
|
16
16
|
throw 6;
|
|
17
17
|
}
|
|
18
18
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { type SortedList } from '../sorted_list/module.f.ts';
|
|
2
|
+
import type { Reduce, Equal } from '../function/operator/module.f.ts';
|
|
3
|
+
import type { Range } from '../range/module.f.ts';
|
|
4
4
|
export type Entry<T> = [T, number];
|
|
5
|
-
export type RangeMap<T> =
|
|
5
|
+
export type RangeMap<T> = SortedList<Entry<T>>;
|
|
6
6
|
export type RangeMapArray<T> = readonly Entry<T>[];
|
|
7
7
|
export type Operators<T> = {
|
|
8
|
-
readonly union:
|
|
9
|
-
readonly equal:
|
|
8
|
+
readonly union: Reduce<T>;
|
|
9
|
+
readonly equal: Equal<T>;
|
|
10
10
|
};
|
|
11
|
-
export type RangeMerge<T> =
|
|
11
|
+
export type RangeMerge<T> = Reduce<RangeMap<T>>;
|
|
12
12
|
export declare const merge: <T>(op: Operators<T>) => RangeMerge<T>;
|
|
13
13
|
export declare const get: <T>(def: T) => (value: number) => (rm: RangeMapArray<T>) => T;
|
|
14
|
-
export declare const fromRange: <T>(def: T) => (r: Range
|
|
14
|
+
export declare const fromRange: <T>(def: T) => (r: Range) => (value: T) => RangeMapArray<T>;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
const { next } = list;
|
|
5
|
-
import * as Option from "../nullable/module.f.js";
|
|
6
|
-
import * as number from "../number/module.f.js";
|
|
7
|
-
const { cmp } = number;
|
|
8
|
-
import * as O from "../function/operator/module.f.js";
|
|
9
|
-
import * as Range from "../range/module.f.js";
|
|
1
|
+
import { genericMerge } from "../sorted_list/module.f.js";
|
|
2
|
+
import { next } from "../list/module.f.js";
|
|
3
|
+
import { cmp } from "../number/module.f.js";
|
|
10
4
|
const reduceOp = union => equal => state => ([aItem, aMax]) => ([bItem, bMax]) => {
|
|
11
5
|
const sign = cmp(aMax)(bMax);
|
|
12
6
|
const min = sign === 1 ? bMax : aMax;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import * as _ from "./module.f.js";
|
|
2
|
-
import
|
|
3
|
-
const { unsafeCmp } = compare;
|
|
2
|
+
import { unsafeCmp } from "../function/compare/module.f.js";
|
|
4
3
|
import * as json from "../../json/module.f.js";
|
|
5
|
-
import
|
|
6
|
-
const { sort } = object;
|
|
4
|
+
import { sort } from "../object/module.f.js";
|
|
7
5
|
import * as sortedSet from "../sorted_set/module.f.js";
|
|
8
6
|
import * as list from "../list/module.f.js";
|
|
9
7
|
import * as operator from "../function/operator/module.f.js";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
type Ok<T> = readonly ['ok', T];
|
|
2
|
-
type Error<E> = readonly ['error', E];
|
|
1
|
+
export type Ok<T> = readonly ['ok', T];
|
|
2
|
+
export type Error<E> = readonly ['error', E];
|
|
3
3
|
export type Result<T, E> = Ok<T> | Error<E>;
|
|
4
4
|
export declare const ok: <T>(value: T) => Ok<T>;
|
|
5
5
|
export declare const error: <E>(e: E) => Error<E>;
|
|
6
6
|
export declare const unwrap: <T, E>(r: Result<T, E>) => T;
|
|
7
|
-
export {};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
export type SortedList<T> =
|
|
1
|
+
import type { Sign } from '../function/compare/module.f.ts';
|
|
2
|
+
import { type List } from '../list/module.f.ts';
|
|
3
|
+
import type { Nullable } from '../nullable/module.f.ts';
|
|
4
|
+
export type SortedList<T> = List<T>;
|
|
5
5
|
type SortedArray<T> = readonly T[];
|
|
6
|
-
type Cmp<T> = (a: T) => (b: T) =>
|
|
7
|
-
export type ReduceOp<T, S> = (state: S) => (a: T) => (b: T) => readonly [
|
|
8
|
-
export type TailReduce<T, S> = (state: S) => (tail:
|
|
6
|
+
type Cmp<T> = (a: T) => (b: T) => Sign;
|
|
7
|
+
export type ReduceOp<T, S> = (state: S) => (a: T) => (b: T) => readonly [Nullable<T>, Sign, S];
|
|
8
|
+
export type TailReduce<T, S> = (state: S) => (tail: List<T>) => List<T>;
|
|
9
9
|
type MergeReduce<T, S> = {
|
|
10
10
|
readonly reduceOp: ReduceOp<T, S>;
|
|
11
11
|
readonly tailReduce: TailReduce<T, S>;
|
|
12
12
|
};
|
|
13
|
-
export declare const genericMerge: <T, S>({ reduceOp, tailReduce }: MergeReduce<T, S>) => (state: S) => (a:
|
|
13
|
+
export declare const genericMerge: <T, S>({ reduceOp, tailReduce }: MergeReduce<T, S>) => (state: S) => (a: List<T>) => (b: List<T>) => List<T>;
|
|
14
14
|
export declare const merge: <T>(cmp: Cmp<T>) => (a: SortedList<T>) => (b: SortedList<T>) => SortedList<T>;
|
|
15
15
|
export declare const find: <T>(cmp: Cmp<T>) => (value: T) => (array: SortedArray<T>) => T | null;
|
|
16
16
|
export {};
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import * as option from "../nullable/module.f.js";
|
|
4
|
-
const { next } = list;
|
|
5
|
-
import * as f from "../function/module.f.js";
|
|
6
|
-
const { identity } = f;
|
|
1
|
+
import { next } from "../list/module.f.js";
|
|
2
|
+
import { identity } from "../function/module.f.js";
|
|
7
3
|
export const genericMerge = ({ reduceOp, tailReduce }) => {
|
|
8
4
|
const f = state => a => b => () => {
|
|
9
5
|
const aResult = next(a);
|
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const { unsafeCmp } = compare;
|
|
1
|
+
import { find, merge } from "./module.f.js";
|
|
2
|
+
import { unsafeCmp } from "../function/compare/module.f.js";
|
|
4
3
|
import * as json from "../../json/module.f.js";
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
const { toArray, countdown, length } = list;
|
|
9
|
-
import * as Map from "../map/module.f.js";
|
|
10
|
-
import * as f from "../function/module.f.js";
|
|
11
|
-
const { flip } = f;
|
|
4
|
+
import { sort } from "../object/module.f.js";
|
|
5
|
+
import { toArray, countdown, length } from "../list/module.f.js";
|
|
6
|
+
import { flip } from "../function/module.f.js";
|
|
12
7
|
const stringify = json.stringify(sort);
|
|
13
8
|
const reverseCmp = flip(unsafeCmp);
|
|
14
9
|
export default {
|
|
15
10
|
sortedMergre: [
|
|
16
11
|
() => {
|
|
17
|
-
const result = stringify(toArray(
|
|
12
|
+
const result = stringify(toArray(merge(unsafeCmp)([2, 3, 4])([1, 3, 5])));
|
|
18
13
|
if (result !== '[1,2,3,4,5]') {
|
|
19
14
|
throw result;
|
|
20
15
|
}
|
|
21
16
|
},
|
|
22
17
|
() => {
|
|
23
|
-
const result = stringify(toArray(
|
|
18
|
+
const result = stringify(toArray(merge(unsafeCmp)([1, 2, 3])([])));
|
|
24
19
|
if (result !== '[1,2,3]') {
|
|
25
20
|
throw result;
|
|
26
21
|
}
|
|
@@ -28,7 +23,7 @@ export default {
|
|
|
28
23
|
() => {
|
|
29
24
|
const n = 10_000;
|
|
30
25
|
const list = countdown(n);
|
|
31
|
-
const result =
|
|
26
|
+
const result = merge(reverseCmp)(list)(list);
|
|
32
27
|
const len = length(result);
|
|
33
28
|
if (len != n) {
|
|
34
29
|
throw result;
|
|
@@ -37,25 +32,25 @@ export default {
|
|
|
37
32
|
],
|
|
38
33
|
find: [
|
|
39
34
|
() => {
|
|
40
|
-
const result =
|
|
35
|
+
const result = find(unsafeCmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
|
|
41
36
|
if (result !== 0) {
|
|
42
37
|
throw result;
|
|
43
38
|
}
|
|
44
39
|
},
|
|
45
40
|
() => {
|
|
46
|
-
const result =
|
|
41
|
+
const result = find(unsafeCmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
|
|
47
42
|
if (result !== null) {
|
|
48
43
|
throw result;
|
|
49
44
|
}
|
|
50
45
|
},
|
|
51
46
|
() => {
|
|
52
|
-
const result =
|
|
47
|
+
const result = find(unsafeCmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
|
|
53
48
|
if (result !== null) {
|
|
54
49
|
throw result;
|
|
55
50
|
}
|
|
56
51
|
},
|
|
57
52
|
() => {
|
|
58
|
-
const result =
|
|
53
|
+
const result = find(unsafeCmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90]);
|
|
59
54
|
if (result !== 80) {
|
|
60
55
|
throw result;
|
|
61
56
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Sign } from '../function/compare/module.f.ts';
|
|
2
2
|
export type SortedSet<T> = readonly T[];
|
|
3
|
-
type Cmp<T> = (a: T) => (b: T) =>
|
|
3
|
+
type Cmp<T> = (a: T) => (b: T) => Sign;
|
|
4
4
|
export declare const union: <T>(cmp: Cmp<T>) => (a: SortedSet<T>) => (b: SortedSet<T>) => SortedSet<T>;
|
|
5
5
|
export declare const intersect: <T>(cmp: Cmp<T>) => (a: SortedSet<T>) => (b: SortedSet<T>) => SortedSet<T>;
|
|
6
6
|
export declare const has: <T>(cmp: Cmp<T>) => (value: T) => (set: SortedSet<T>) => boolean;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const { toArray } = list;
|
|
4
|
-
import * as sortedList from "../sorted_list/module.f.js";
|
|
5
|
-
const { merge, genericMerge, find } = sortedList;
|
|
1
|
+
import { toArray } from "../list/module.f.js";
|
|
2
|
+
import { merge, genericMerge, find } from "../sorted_list/module.f.js";
|
|
6
3
|
export const union = cmp => a => b => toArray(merge(cmp)(a)(b));
|
|
7
4
|
export const intersect = cmp => a => b => toArray(intersectMerge(cmp)(a)(b));
|
|
8
5
|
const tailReduce = () => () => null;
|