functionalscript 0.0.592 → 0.1.594
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/.github/workflows/ci.yml +3 -3
- package/README.md +1 -0
- package/com/cpp/{module.f.cjs → module.f.mjs} +22 -21
- package/com/cpp/{test.f.cjs → test.f.mjs} +2 -2
- package/com/cpp/testlib.f.mjs +9 -0
- package/com/cs/{module.f.cjs → module.f.mjs} +20 -19
- package/com/cs/{test.f.cjs → test.f.mjs} +2 -2
- package/com/cs/testlib.f.mjs +10 -0
- package/com/rust/{module.f.cjs → module.f.mjs} +37 -35
- package/com/rust/{test.f.cjs → test.f.mjs} +2 -2
- package/com/rust/testlib.f.mjs +10 -0
- package/com/test/{build.f.cjs → build.f.mjs} +6 -6
- package/com/test/{build.cjs → build.mjs} +16 -8
- package/com/types/{module.f.cjs → module.f.mjs} +9 -8
- package/com/types/{testlib.f.cjs → testlib.f.mjs} +2 -2
- package/commonjs/build/{module.f.cjs → module.f.mjs} +23 -23
- package/commonjs/build/{test.f.cjs → test.f.mjs} +13 -12
- package/commonjs/module/function/{module.f.cjs → module.f.mjs} +4 -4
- package/commonjs/module/{module.f.cjs → module.f.mjs} +3 -5
- package/commonjs/module.f.mjs +11 -0
- package/commonjs/{module.cjs → module.mjs} +8 -6
- package/commonjs/package/dependencies/{module.f.cjs → module.f.mjs} +5 -5
- package/commonjs/package/dependencies/{test.f.cjs → test.f.mjs} +2 -2
- package/commonjs/package/{module.f.cjs → module.f.mjs} +7 -6
- package/commonjs/package/{test.f.cjs → test.f.mjs} +2 -2
- package/commonjs/path/{module.f.cjs → module.f.mjs} +15 -14
- package/commonjs/path/{test.f.cjs → test.f.mjs} +16 -14
- package/commonjs/{test.cjs → test.mjs} +4 -4
- package/dev/{module.f.cjs → module.f.mjs} +1 -1
- package/dev/module.mjs +5 -3
- package/dev/test/{module.f.cjs → module.f.mjs} +21 -9
- package/dev/{test.f.cjs → test.f.mjs} +1 -1
- package/dev/test.mjs +1 -1
- package/djs/{module.f.cjs → module.f.mjs} +18 -15
- package/djs/parser/{module.f.cjs → module.f.mjs} +29 -28
- package/djs/parser/{test.f.cjs → test.f.mjs} +10 -8
- package/djs/{test.f.cjs → test.f.mjs} +7 -5
- package/djs/tokenizer/{module.f.cjs → module.f.mjs} +19 -18
- package/djs/tokenizer/{test.f.cjs → test.f.mjs} +9 -7
- package/fsc/{module.f.cjs → module.f.mjs} +17 -16
- package/fsc/{test.f.cjs → test.f.mjs} +6 -4
- package/fsm/{module.f.cjs → module.f.mjs} +28 -24
- package/fsm/{test.f.cjs → test.f.mjs} +13 -9
- package/html/{module.f.cjs → module.f.mjs} +16 -13
- package/html/{test.f.cjs → test.f.mjs} +5 -5
- package/index.f.mjs +45 -35
- package/issues/README.md +15 -0
- package/js/tokenizer/{module.f.cjs → module.f.mjs} +52 -51
- package/js/tokenizer/{test.f.cjs → test.f.mjs} +9 -7
- package/json/{module.f.cjs → module.f.mjs} +18 -17
- package/json/parser/{module.f.cjs → module.f.mjs} +27 -26
- package/json/parser/{test.f.cjs → test.f.mjs} +10 -8
- package/json/serializer/{module.f.cjs → module.f.mjs} +12 -12
- package/json/serializer/{test.f.cjs → test.f.mjs} +4 -3
- package/json/{test.f.cjs → test.f.mjs} +6 -4
- package/json/tokenizer/{module.f.cjs → module.f.mjs} +16 -15
- package/json/tokenizer/{test.f.cjs → test.f.mjs} +9 -7
- package/jsr.json +1 -1
- package/nodejs/version/main.mjs +5 -0
- package/nodejs/version/{module.f.cjs → module.f.mjs} +2 -2
- package/nodejs/version/{test.f.cjs → test.f.mjs} +5 -5
- package/package.json +3 -3
- package/prime_field/{module.f.cjs → module.f.mjs} +6 -5
- package/prime_field/{test.f.cjs → test.f.mjs} +3 -2
- package/secp/{module.f.cjs → module.f.mjs} +7 -6
- package/secp/{test.f.cjs → test.f.mjs} +6 -6
- package/sha2/{module.f.cjs → module.f.mjs} +5 -5
- package/sha2/{test.f.cjs → test.f.mjs} +7 -6
- package/text/ascii/{module.f.cjs → module.f.mjs} +3 -3
- package/text/ascii/test.f.mjs +14 -0
- package/text/{module.f.cjs → module.f.mjs} +6 -6
- package/text/sgr/{module.f.cjs → module.f.mjs} +1 -1
- package/text/{test.f.cjs → test.f.mjs} +5 -4
- package/text/utf16/{module.f.cjs → module.f.mjs} +16 -14
- package/text/utf16/{test.f.cjs → test.f.mjs} +7 -6
- package/text/utf8/{module.f.cjs → module.f.mjs} +11 -11
- package/text/utf8/{test.f.cjs → test.f.mjs} +6 -5
- package/tsconfig.json +2 -2
- package/types/array/{module.f.cjs → module.f.mjs} +2 -2
- package/types/array/{test.f.cjs → test.f.mjs} +5 -4
- package/types/bigfloat/{module.f.cjs → module.f.mjs} +3 -3
- package/types/bigfloat/{test.f.cjs → test.f.mjs} +3 -2
- package/types/bigint/{module.f.cjs → module.f.mjs} +8 -7
- package/types/bigint/{test.f.cjs → test.f.mjs} +3 -2
- package/types/btree/find/{module.f.cjs → module.f.mjs} +12 -12
- package/types/btree/find/{test.f.cjs → test.f.mjs} +11 -9
- package/types/btree/{module.f.cjs → module.f.mjs} +7 -12
- package/types/btree/remove/{module.f.cjs → module.f.mjs} +17 -16
- package/types/btree/remove/{test.f.cjs → test.f.mjs} +9 -7
- package/types/btree/set/{module.f.cjs → module.f.mjs} +9 -9
- package/types/btree/set/{test.f.cjs → test.f.mjs} +8 -6
- package/types/btree/{test.f.cjs → test.f.mjs} +23 -20
- package/types/btree/types/{module.f.cjs → module.f.mjs} +1 -1
- package/types/byte_set/{module.f.cjs → module.f.mjs} +8 -7
- package/types/byte_set/{test.f.cjs → test.f.mjs} +8 -7
- package/types/function/compare/{module.f.cjs → module.f.mjs} +2 -2
- package/types/function/compare/{test.f.cjs → test.f.mjs} +3 -2
- package/types/function/{module.f.cjs → module.f.mjs} +1 -5
- package/types/function/operator/{module.f.cjs → module.f.mjs} +1 -1
- package/types/function/{test.f.cjs → test.f.mjs} +4 -2
- package/types/list/{module.f.cjs → module.f.mjs} +12 -12
- package/types/list/{test.f.cjs → test.f.mjs} +13 -11
- package/types/map/{module.f.cjs → module.f.mjs} +21 -18
- package/types/map/{test.f.cjs → test.f.mjs} +5 -4
- package/types/nibble_set/{module.f.cjs → module.f.mjs} +1 -1
- package/types/nibble_set/{test.f.cjs → test.f.mjs} +4 -3
- package/types/nullable/{module.f.cjs → module.f.mjs} +1 -1
- package/types/nullable/{test.f.cjs → test.f.mjs} +2 -2
- package/types/number/module.f.mjs +26 -0
- package/types/number/{test.f.cjs → test.f.mjs} +3 -2
- package/types/object/{module.f.cjs → module.f.mjs} +6 -6
- package/types/object/{test.f.cjs → test.f.mjs} +2 -2
- package/types/range/{module.f.cjs → module.f.mjs} +1 -1
- package/types/range/{test.f.cjs → test.f.mjs} +2 -2
- package/types/range_map/{module.f.cjs → module.f.mjs} +16 -15
- package/types/range_map/{test.f.cjs → test.f.mjs} +35 -33
- package/types/result/{module.f.cjs → module.f.mjs} +1 -1
- package/types/result/{module.cjs → module.mjs} +3 -3
- package/types/sorted_list/{module.f.cjs → module.f.mjs} +11 -10
- package/types/sorted_list/{test.f.cjs → test.f.mjs} +14 -10
- package/types/sorted_set/{module.f.cjs → module.f.mjs} +8 -7
- package/types/sorted_set/{test.f.cjs → test.f.mjs} +14 -10
- package/types/string/{module.f.cjs → module.f.mjs} +8 -7
- package/types/string/{test.f.cjs → test.f.mjs} +5 -3
- package/types/string_set/{module.f.cjs → module.f.mjs} +15 -10
- package/types/string_set/{test.f.cjs → test.f.mjs} +2 -2
- package/com/cpp/testlib.f.cjs +0 -6
- package/com/cs/testlib.f.cjs +0 -6
- package/com/module.f.cjs +0 -6
- package/com/rust/testlib.f.cjs +0 -6
- package/commonjs/module.f.cjs +0 -20
- package/nodejs/module.f.cjs +0 -4
- package/nodejs/version/main.cjs +0 -6
- package/text/ascii/test.f.cjs +0 -12
- package/types/number/module.f.cjs +0 -24
- package/types/object/test.html +0 -9
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const {
|
|
1
|
+
import list, * as List from '../../types/list/module.f.mjs'
|
|
2
|
+
import operator, * as Operator from '../../types/function/operator/module.f.mjs'
|
|
3
|
+
import range from '../../types/range/module.f.mjs'
|
|
4
|
+
const { contains } = range
|
|
5
|
+
import f from '../../types/function/module.f.mjs'
|
|
6
|
+
const { fn } = f
|
|
5
7
|
const { map, flat, stateScan, reduce, flatMap, empty } = list
|
|
6
8
|
|
|
7
9
|
/** @typedef {u16|null} WordOrEof */
|
|
@@ -29,7 +31,7 @@ const errorMask = 0b1000_0000_0000_0000_0000_0000_0000_0000
|
|
|
29
31
|
/** @type {(a: i32) => boolean} */
|
|
30
32
|
const isSupplementaryPlane = contains([0x01_0000, 0x10_ffff])
|
|
31
33
|
|
|
32
|
-
/** @type {(input: i32) =>
|
|
34
|
+
/** @type {(input: i32) => List.List<u16>} */
|
|
33
35
|
const codePointToUtf16 = codePoint => {
|
|
34
36
|
if (isBmpCodePoint(codePoint)) { return [codePoint] }
|
|
35
37
|
if (isSupplementaryPlane(codePoint)) {
|
|
@@ -45,7 +47,7 @@ const fromCodePointList = flatMap(codePointToUtf16)
|
|
|
45
47
|
|
|
46
48
|
const u16 = contains([0x0000, 0xFFFF])
|
|
47
49
|
|
|
48
|
-
/** @type {
|
|
50
|
+
/** @type {Operator.StateScan<u16, Utf16State, List.List<i32>>} */
|
|
49
51
|
const utf16ByteToCodePointOp = state => word => {
|
|
50
52
|
if (!u16(word)) {
|
|
51
53
|
return [[0xffffffff], state]
|
|
@@ -65,21 +67,21 @@ const utf16ByteToCodePointOp = state => word => {
|
|
|
65
67
|
return [[state | errorMask, word | errorMask], null]
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
/** @type {(state: Utf16State) => readonly[
|
|
70
|
+
/** @type {(state: Utf16State) => readonly[List.List<i32>, Utf16State]} */
|
|
69
71
|
const utf16EofToCodePointOp = state => [state === null ? empty : [state | errorMask], null]
|
|
70
72
|
|
|
71
|
-
/** @type {
|
|
73
|
+
/** @type {Operator.StateScan<WordOrEof, Utf16State, List.List<i32>>} */
|
|
72
74
|
const utf16ByteOrEofToCodePointOp = state => input => input === null ? utf16EofToCodePointOp(state) : utf16ByteToCodePointOp(state)(input)
|
|
73
75
|
|
|
74
|
-
/** @type {
|
|
76
|
+
/** @type {List.List<WordOrEof>} */
|
|
75
77
|
const eofList = [null]
|
|
76
78
|
|
|
77
|
-
/** @type {(input:
|
|
79
|
+
/** @type {(input: List.List<u16>) => List.List<i32>} */
|
|
78
80
|
const toCodePointList = input => flat(stateScan(utf16ByteOrEofToCodePointOp)(null)(flat([input, eofList])))
|
|
79
81
|
|
|
80
|
-
/** @type {(s: string) =>
|
|
82
|
+
/** @type {(s: string) => List.List<u16>} */
|
|
81
83
|
const stringToList = s => {
|
|
82
|
-
/** @type {(i: number) =>
|
|
84
|
+
/** @type {(i: number) => List.Result<number>} */
|
|
83
85
|
const at = i => {
|
|
84
86
|
const first = s.charCodeAt(i)
|
|
85
87
|
return isNaN(first) ? empty : { first, tail: () => at(i + 1) }
|
|
@@ -87,12 +89,12 @@ const stringToList = s => {
|
|
|
87
89
|
return at(0)
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
/** @type {(input:
|
|
92
|
+
/** @type {(input: List.List<u16>) => string} */
|
|
91
93
|
const listToString = fn(map(String.fromCharCode))
|
|
92
94
|
.then(reduce(operator.concat)(''))
|
|
93
95
|
.result
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
export default {
|
|
96
98
|
/** @readonly */
|
|
97
99
|
fromCodePointList,
|
|
98
100
|
/** @readonly */
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
import encoding from './module.f.mjs'
|
|
2
|
+
import json, * as jsonT from '../../json/module.f.mjs'
|
|
3
|
+
import o from '../../types/object/module.f.mjs'
|
|
4
|
+
const { sort } = o
|
|
5
|
+
import list from '../../types/list/module.f.mjs'
|
|
5
6
|
|
|
6
|
-
/** @type {(a: readonly
|
|
7
|
+
/** @type {(a: readonly jsonT.Unknown[]) => string} */
|
|
7
8
|
const stringify = a => json.stringify(sort)(a)
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
export default {
|
|
10
11
|
toCodePointList: [
|
|
11
12
|
() => {
|
|
12
13
|
const result = stringify(list.toArray(encoding.toCodePointList([-1, 65536])))
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import list, * as List from '../../types/list/module.f.mjs'
|
|
2
|
+
import * as operator from '../../types/function/operator/module.f.mjs'
|
|
3
|
+
import * as arrayT from '../../types/array/module.f.mjs'
|
|
4
4
|
const { flatMap, flat, stateScan } = list
|
|
5
5
|
|
|
6
6
|
/** @typedef {u8|null} ByteOrEof */
|
|
7
7
|
|
|
8
|
-
/** @typedef {
|
|
8
|
+
/** @typedef {arrayT.Array1<number>|arrayT.Array2<number>|arrayT.Array3<number>} Utf8NonEmptyState */
|
|
9
9
|
|
|
10
10
|
/** @typedef {null|Utf8NonEmptyState} Utf8State */
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ const { flatMap, flat, stateScan } = list
|
|
|
15
15
|
|
|
16
16
|
const errorMask = 0b1000_0000_0000_0000_0000_0000_0000_0000
|
|
17
17
|
|
|
18
|
-
/** @type {(input:number) =>
|
|
18
|
+
/** @type {(input:number) => List.List<u8>} */
|
|
19
19
|
const codePointToUtf8 = input => {
|
|
20
20
|
if (input >= 0x0000 && input <= 0x007f) { return [input & 0b01111_1111] }
|
|
21
21
|
if (input >= 0x0080 && input <= 0x07ff) { return [input >> 6 | 0b1100_0000, input & 0b0011_1111 | 0b1000_0000] }
|
|
@@ -58,7 +58,7 @@ const utf8StateToError = state => {
|
|
|
58
58
|
return x | errorMask
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
/** @type {operator.StateScan<number, Utf8State,
|
|
61
|
+
/** @type {operator.StateScan<number, Utf8State, List.List<i32>>} */
|
|
62
62
|
const utf8ByteToCodePointOp = state => byte => {
|
|
63
63
|
if (byte < 0x00 || byte > 0xff) {
|
|
64
64
|
return [[errorMask], state]
|
|
@@ -94,20 +94,20 @@ const utf8ByteToCodePointOp = state => byte => {
|
|
|
94
94
|
return [[error, byte | errorMask], null]
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
/** @type {(state: Utf8State) => readonly[
|
|
97
|
+
/** @type {(state: Utf8State) => readonly[List.List<i32>, Utf8State]} */
|
|
98
98
|
const utf8EofToCodePointOp = state =>
|
|
99
99
|
[state === null ? null : [utf8StateToError(state)], null]
|
|
100
100
|
|
|
101
|
-
/** @type {operator.StateScan<ByteOrEof, Utf8State,
|
|
101
|
+
/** @type {operator.StateScan<ByteOrEof, Utf8State, List.List<i32>>} */
|
|
102
102
|
const utf8ByteOrEofToCodePointOp = state => input => input === null ? utf8EofToCodePointOp(state) : utf8ByteToCodePointOp(state)(input)
|
|
103
103
|
|
|
104
|
-
/** @type {
|
|
104
|
+
/** @type {List.List<ByteOrEof>} */
|
|
105
105
|
const eofList = [null]
|
|
106
106
|
|
|
107
|
-
/** @type {(input:
|
|
107
|
+
/** @type {(input: List.List<u8>) => List.List<i32>} */
|
|
108
108
|
const toCodePointList = input => flat(stateScan(utf8ByteOrEofToCodePointOp)(null)(flat([input, eofList])))
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
export default {
|
|
111
111
|
/** @readonly */
|
|
112
112
|
fromCodePointList,
|
|
113
113
|
/** @readonly */
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
import encoding from './module.f.mjs'
|
|
2
|
+
import json from '../../json/module.f.mjs'
|
|
3
|
+
import o from '../../types/object/module.f.mjs'
|
|
4
|
+
const { sort } = o
|
|
5
|
+
import list from '../../types/list/module.f.mjs'
|
|
5
6
|
|
|
6
7
|
const stringify = json.stringify(sort)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
export default {
|
|
9
10
|
toCodePoint: [
|
|
10
11
|
() => {
|
|
11
12
|
const result = stringify(list.toArray(encoding.toCodePointList([-1, 256])))
|
package/tsconfig.json
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
25
|
|
|
26
26
|
/* Modules */
|
|
27
|
-
"module": "
|
|
27
|
+
"module": "ES2022", /* Specify what module code is generated. */
|
|
28
28
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
29
29
|
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
30
30
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
|
|
34
34
|
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
35
35
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
36
|
-
"resolveJsonModule": true, /* Enable importing .json files */
|
|
36
|
+
// "resolveJsonModule": true, /* Enable importing .json files */
|
|
37
37
|
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
|
38
38
|
|
|
39
39
|
/* JavaScript Support */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import option from '../nullable/module.f.mjs'
|
|
2
2
|
const { map } = option
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -117,7 +117,7 @@ const splitLast = a => {
|
|
|
117
117
|
return [uncheckHead(a), lastA]
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
export default {
|
|
121
121
|
/** @readonly */
|
|
122
122
|
at,
|
|
123
123
|
/** @readnly */
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import _ from './module.f.mjs'
|
|
2
|
+
import json from '../../json/module.f.mjs'
|
|
3
|
+
import o from '../object/module.f.mjs'
|
|
4
|
+
const { sort } = o
|
|
4
5
|
|
|
5
6
|
const stringify = json.stringify(sort)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
export default {
|
|
8
9
|
stringify: () => {
|
|
9
10
|
const result = stringify([1, 20, 300])
|
|
10
11
|
if (result !== '[1,20,300]') { throw result }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
const { abs, sign } =
|
|
1
|
+
import bi from '../bigint/module.f.mjs'
|
|
2
|
+
const { abs, sign } = bi
|
|
3
3
|
|
|
4
4
|
/** @typedef {readonly[bigint,number]} BigFloat */
|
|
5
5
|
|
|
@@ -86,7 +86,7 @@ const decToBin = dec => {
|
|
|
86
86
|
return multiply(r53)(s)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
export default {
|
|
90
90
|
/** @readonly */
|
|
91
91
|
decToBin,
|
|
92
92
|
/** @readonly */
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import compare, * as compareT from '../function/compare/module.f.mjs'
|
|
2
|
+
import op, * as Op from '../function/operator/module.f.mjs'
|
|
3
3
|
const { unsafeCmp } = compare
|
|
4
|
-
|
|
4
|
+
import list from '../list/module.f.mjs'
|
|
5
|
+
const { reduce } = list
|
|
5
6
|
|
|
6
|
-
/** @typedef {
|
|
7
|
+
/** @typedef {Op.Unary<bigint, bigint>} Unary*/
|
|
7
8
|
|
|
8
9
|
/** @type {(a: bigint) => (b: bigint) => bigint} */
|
|
9
10
|
const addition = a => b => a + b
|
|
@@ -13,7 +14,7 @@ const sum = reduce(addition)(0n)
|
|
|
13
14
|
/** @type {(a: bigint) => bigint} */
|
|
14
15
|
const abs = a => a >= 0 ? a : -a
|
|
15
16
|
|
|
16
|
-
/** @type {(a: bigint) =>
|
|
17
|
+
/** @type {(a: bigint) => compareT.Sign} */
|
|
17
18
|
const sign = a => unsafeCmp(a)(0n)
|
|
18
19
|
|
|
19
20
|
/** @type {(a: bigint) => string} */
|
|
@@ -23,7 +24,7 @@ const serialize = a => `${a}n`
|
|
|
23
24
|
* @template T
|
|
24
25
|
* @typedef {{
|
|
25
26
|
* readonly 0: T
|
|
26
|
-
* readonly add:
|
|
27
|
+
* readonly add: Op.Reduce<T>
|
|
27
28
|
* }} Additive
|
|
28
29
|
*/
|
|
29
30
|
|
|
@@ -117,7 +118,7 @@ const bitLength = v => {
|
|
|
117
118
|
return log2(v) + 1n
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
|
|
121
|
+
export default {
|
|
121
122
|
/** @readonly */
|
|
122
123
|
addition,
|
|
123
124
|
/** @readonly */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import _ from './module.f.mjs'
|
|
2
|
+
const { sum, abs, serialize, log2, bitLength } = _
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
export default {
|
|
4
5
|
sum: () => {
|
|
5
6
|
const result = sum([2n, 3n, 4n, 5n])
|
|
6
7
|
if (result !== 14n) { throw result }
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as _ from '../types/module.f.mjs'
|
|
2
|
+
import list, * as List from '../../list/module.f.mjs'
|
|
3
|
+
import cmp, * as cmpT from '../../function/compare/module.f.mjs'
|
|
4
4
|
const { index3, index5 } = cmp
|
|
5
|
-
|
|
5
|
+
import array, * as arrayT from '../../array/module.f.mjs'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @template T
|
|
9
|
-
* @typedef {readonly[
|
|
9
|
+
* @typedef {readonly[cmpT.Index3, _.Leaf1<T>]} FirstLeaf1
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -16,7 +16,7 @@ const array = require('../../array/module.f.cjs')
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @template T
|
|
19
|
-
* @typedef {readonly[
|
|
19
|
+
* @typedef {readonly[cmpT.Index5, _.Leaf2<T>]} FirstLeaf2
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -50,7 +50,7 @@ const child = item =>
|
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* @template T
|
|
53
|
-
* @typedef {
|
|
53
|
+
* @typedef {List.List<PathItem<T>>} Path
|
|
54
54
|
*/
|
|
55
55
|
|
|
56
56
|
/**
|
|
@@ -61,19 +61,19 @@ const child = item =>
|
|
|
61
61
|
* }} Result<T>
|
|
62
62
|
*/
|
|
63
63
|
|
|
64
|
-
/** @type {<T>(c:
|
|
64
|
+
/** @type {<T>(c: cmpT.Compare<T>) => (node: _.Node<T>) => Result<T>} */
|
|
65
65
|
const find = c => {
|
|
66
66
|
const i3 = index3(c)
|
|
67
67
|
const i5 = index5(c)
|
|
68
|
-
/** @typedef {typeof c extends
|
|
68
|
+
/** @typedef {typeof c extends cmpT.Compare<infer T> ? T : never} T */
|
|
69
69
|
/** @type {(prior: Path<T>) => (node: _.Node<T>) => Result<T>} */
|
|
70
70
|
const f = tail => node => {
|
|
71
|
-
/** @type {(index:
|
|
71
|
+
/** @type {(index: arrayT.KeyOf<typeof node>) => Result<T>} */
|
|
72
72
|
const append = index => {
|
|
73
73
|
const first = /** @type {PathItem<T>} */([index, node])
|
|
74
74
|
return f({ first, tail })(child(first))
|
|
75
75
|
}
|
|
76
|
-
/** @type {(index:
|
|
76
|
+
/** @type {(index: arrayT.KeyOf<typeof node>) => Result<T>} */
|
|
77
77
|
const done = index => ({ first: /** @type {First<T>} */([index, node]), tail })
|
|
78
78
|
switch (node.length) {
|
|
79
79
|
case 1: { return done(i3(node[0])) }
|
|
@@ -123,7 +123,7 @@ const value = ([i, r]) => {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
export default {
|
|
127
127
|
/** @readonly */
|
|
128
128
|
find,
|
|
129
129
|
/** @readonly */
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import _, * as T from './module.f.mjs'
|
|
2
|
+
import list from '../../list/module.f.mjs'
|
|
3
|
+
import json, * as jsonT from '../../../json/module.f.mjs'
|
|
4
|
+
import o from '../../object/module.f.mjs'
|
|
5
|
+
const { sort } = o
|
|
6
|
+
import * as btree from '../types/module.f.mjs'
|
|
7
|
+
import string from '../../string/module.f.mjs'
|
|
8
|
+
const { cmp } = string
|
|
9
|
+
import s from '../set/module.f.mjs'
|
|
8
10
|
|
|
9
11
|
const jsonStr = json.stringify(sort)
|
|
10
12
|
|
|
11
13
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
12
14
|
const set = node => value => s.set(cmp(value))(() => value)(node)
|
|
13
15
|
|
|
14
|
-
/** @type {(r:
|
|
16
|
+
/** @type {(r: T.Result<jsonT.Unknown>) => string} */
|
|
15
17
|
const str = r => jsonStr(list.toArray(list.map(x => x[0])(r)))
|
|
16
18
|
|
|
17
19
|
/** @type {(i: string) => (m: btree.Node<string>) => string} */
|
|
@@ -113,4 +115,4 @@ const test = () => {
|
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
|
|
116
|
-
|
|
118
|
+
export default test
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import list, * as List from '../list/module.f.mjs'
|
|
2
2
|
const { flat } = list
|
|
3
|
-
|
|
4
|
-
const
|
|
3
|
+
import n from '../nullable/module.f.mjs'
|
|
4
|
+
const { map } = n
|
|
5
|
+
import * as _ from './types/module.f.mjs'
|
|
5
6
|
|
|
6
|
-
/** @type {<T>(node: _.Node<T>) =>
|
|
7
|
+
/** @type {<T>(node: _.Node<T>) => List.Thunk<T>} */
|
|
7
8
|
const nodeValues = node => () => {
|
|
8
9
|
switch (node.length) {
|
|
9
10
|
case 1: case 2: { return node }
|
|
@@ -26,18 +27,12 @@ const nodeValues = node => () => {
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
/** @type {<T>(tree: _.Tree<T>) =>
|
|
30
|
+
/** @type {<T>(tree: _.Tree<T>) => List.List<T>} */
|
|
30
31
|
const values = map(nodeValues)
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
export default {
|
|
33
34
|
/** @readonly */
|
|
34
35
|
empty: null,
|
|
35
36
|
/** @readonly */
|
|
36
|
-
find: require('./find/module.f.cjs'),
|
|
37
|
-
/** @readonly */
|
|
38
|
-
remove: require('./remove/module.f.cjs'),
|
|
39
|
-
/** @readonly */
|
|
40
|
-
set: require('./set/module.f.cjs'),
|
|
41
|
-
/** @readonly */
|
|
42
37
|
values,
|
|
43
38
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as _ from '../types/module.f.mjs'
|
|
2
|
+
import cmp, * as cmpT from '../../function/compare/module.f.mjs'
|
|
3
|
+
import find, * as findT from '../find/module.f.mjs'
|
|
4
|
+
import list from '../../list/module.f.mjs'
|
|
5
5
|
const { fold, concat, next } = list
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import array, * as arrayT from '../../array/module.f.mjs'
|
|
7
|
+
import n from '../../nullable/module.f.mjs'
|
|
8
|
+
const { map } = n
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @template T
|
|
@@ -15,11 +16,11 @@ const { map } = require('../../nullable/module.f.cjs')
|
|
|
15
16
|
* @template T
|
|
16
17
|
* @typedef {{
|
|
17
18
|
* readonly first: Leaf01<T>,
|
|
18
|
-
* readonly tail:
|
|
19
|
+
* readonly tail: findT.Path<T>
|
|
19
20
|
* }} RemovePath
|
|
20
21
|
*/
|
|
21
22
|
|
|
22
|
-
/** @type {<T>(tail:
|
|
23
|
+
/** @type {<T>(tail: findT.Path<T>) => (n: _.Node<T>) => readonly[T, RemovePath<T>]} */
|
|
23
24
|
const path = tail => n => {
|
|
24
25
|
switch (n.length) {
|
|
25
26
|
case 1: { return [n[0], { first: null, tail }] }
|
|
@@ -93,10 +94,10 @@ const initValue1 = a => n => {
|
|
|
93
94
|
* @typedef {(a: A) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>} Merge
|
|
94
95
|
*/
|
|
95
96
|
|
|
96
|
-
/** @type {<A, T>(ms:
|
|
97
|
+
/** @type {<A, T>(ms: arrayT.Array2<Merge<A, T>>) => (i: findT.PathItem<T>) => (a: A) => Branch<T>} */
|
|
97
98
|
const reduceX = ms => ([i, n]) => a => {
|
|
98
99
|
const [m0, m2] = ms
|
|
99
|
-
/** @typedef {typeof ms extends
|
|
100
|
+
/** @typedef {typeof ms extends arrayT.Array2<Merge<infer A, infer T>> ? [A,T] : never} AT */
|
|
100
101
|
/** @typedef {AT[0]} A */
|
|
101
102
|
/** @typedef {AT[1]} T */
|
|
102
103
|
/** @type {(m: Merge<A, T>) => Branch<T>} */
|
|
@@ -115,15 +116,15 @@ const reduce = fold(reduceX([reduceValue0, reduceValue2]))
|
|
|
115
116
|
|
|
116
117
|
const initReduce = reduceX([initValue0, initValue1])
|
|
117
118
|
|
|
118
|
-
/** @type {<T>(c:
|
|
119
|
+
/** @type {<T>(c: cmpT.Compare<T>) => (node: _.Node<T>) => _.Tree<T>} */
|
|
119
120
|
const nodeRemove = c => node => {
|
|
120
|
-
/** @typedef {typeof c extends
|
|
121
|
+
/** @typedef {typeof c extends cmpT.Compare<infer T> ? T : never} T */
|
|
121
122
|
/** @type {() => null | RemovePath<T>} */
|
|
122
123
|
const f = () => {
|
|
123
124
|
const { first, tail } = find.find(c)(node)
|
|
124
|
-
/** @type {(n: _.Node<T>) => (f: (v: T) =>
|
|
125
|
+
/** @type {(n: _.Node<T>) => (f: (v: T) => findT.PathItem<T>) => RemovePath<T>} */
|
|
125
126
|
const branch = n => f => {
|
|
126
|
-
const [v, p] = path(/** @type {
|
|
127
|
+
const [v, p] = path(/** @type {findT.Path<T>} */(null))(n)
|
|
127
128
|
return { first: p.first, tail: concat(p.tail)({ first: f(v), tail }) }
|
|
128
129
|
}
|
|
129
130
|
const [i, n] = first
|
|
@@ -155,10 +156,10 @@ const nodeRemove = c => node => {
|
|
|
155
156
|
return result.length === 1 ? result[0] : result
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
/** @type {<T>(c:
|
|
159
|
+
/** @type {<T>(c: cmpT.Compare<T>) => (tree: _.Tree<T>) => _.Tree<T>} */
|
|
159
160
|
const remove = c => map(nodeRemove(c))
|
|
160
161
|
|
|
161
|
-
|
|
162
|
+
export default {
|
|
162
163
|
/** @readonly */
|
|
163
164
|
nodeRemove,
|
|
164
165
|
/** @readonly */
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
1
|
+
import _ from './module.f.mjs'
|
|
2
|
+
import * as btree from '../types/module.f.mjs'
|
|
3
|
+
import s from '../set/module.f.mjs'
|
|
4
|
+
import str from '../../string/module.f.mjs'
|
|
5
|
+
const { cmp } = str
|
|
6
|
+
import json from '../../../json/module.f.mjs'
|
|
7
|
+
import o from '../../object/module.f.mjs'
|
|
8
|
+
const { sort } = o
|
|
7
9
|
|
|
8
10
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
9
11
|
const set = node => value => s.set(cmp(value))(() => value)(node)
|
|
@@ -486,7 +488,7 @@ const test2 = () => {
|
|
|
486
488
|
}
|
|
487
489
|
}
|
|
488
490
|
|
|
489
|
-
|
|
491
|
+
export default {
|
|
490
492
|
test,
|
|
491
493
|
test2,
|
|
492
494
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as _ from '../types/module.f.mjs'
|
|
2
|
+
import btreeFind, * as btreeFindT from '../find/module.f.mjs'
|
|
3
3
|
const { find } = btreeFind
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import cmp, * as cmpT from '../../function/compare/module.f.mjs'
|
|
5
|
+
import list from '../../list/module.f.mjs'
|
|
6
6
|
const { fold } = list
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -13,7 +13,7 @@ const { fold } = list
|
|
|
13
13
|
/** @type {<T>(b: _.Branch5<T> | _.Branch7<T>) => Branch1To3<T>} */
|
|
14
14
|
const b57 = b => b.length === 5 ? [b] : [[b[0], b[1], b[2]], b[3], [b[4], b[5], b[6]]]
|
|
15
15
|
|
|
16
|
-
/** @type {<T>(i:
|
|
16
|
+
/** @type {<T>(i: btreeFindT.PathItem<T>) => (a: Branch1To3<T>) => Branch1To3<T>} */
|
|
17
17
|
const reduceOp = ([i, x]) => a => {
|
|
18
18
|
switch (i) {
|
|
19
19
|
case 0: {
|
|
@@ -36,11 +36,11 @@ const reduceOp = ([i, x]) => a => {
|
|
|
36
36
|
|
|
37
37
|
const reduceBranch = fold(reduceOp)
|
|
38
38
|
|
|
39
|
-
/** @type {<T>(c:
|
|
39
|
+
/** @type {<T>(c: cmpT.Compare<T>) => (g: (value: T | null) => T) => (node: _.Node<T>) => _.Node<T>} */
|
|
40
40
|
const nodeSet = c => g => node => {
|
|
41
41
|
const { first, tail } = find(c)(node)
|
|
42
42
|
const [i, x] = first;
|
|
43
|
-
/** @typedef {typeof c extends
|
|
43
|
+
/** @typedef {typeof c extends cmpT.Compare<infer T> ? T : never} T */
|
|
44
44
|
/** @type {() => Branch1To3<T>} */
|
|
45
45
|
const f = () => {
|
|
46
46
|
switch (i) {
|
|
@@ -87,10 +87,10 @@ const nodeSet = c => g => node => {
|
|
|
87
87
|
return r.length === 1 ? r[0] : r
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
/** @type {<T>(c:
|
|
90
|
+
/** @type {<T>(c: cmpT.Compare<T>) => (f: (value: T|null) => T) => (tree: _.Tree<T>) => _.Node<T>} */
|
|
91
91
|
const set = c => f => tree => tree === null ? [f(null)] : nodeSet(c)(f)(tree)
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
export default {
|
|
94
94
|
/** @readonly */
|
|
95
95
|
set,
|
|
96
96
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
import _ from './module.f.mjs'
|
|
2
|
+
import * as btree from '../types/module.f.mjs'
|
|
3
|
+
import s from '../../string/module.f.mjs'
|
|
4
|
+
const { cmp } = s
|
|
5
|
+
import json, * as jsonT from '../../../json/module.f.mjs'
|
|
6
|
+
import o from '../../object/module.f.mjs'
|
|
7
|
+
const { sort } = o
|
|
6
8
|
|
|
7
9
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
8
10
|
const set = node => value => _.set(cmp(value))(() => value)(node)
|
|
@@ -380,4 +382,4 @@ const test = [
|
|
|
380
382
|
}
|
|
381
383
|
]
|
|
382
384
|
|
|
383
|
-
|
|
385
|
+
export default test
|