functionalscript 0.0.486 → 0.0.488
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.cjs +1 -2
- package/com/cpp/test.f.cjs +1 -1
- package/com/cpp/testlib.f.cjs +1 -1
- package/com/rust/module.f.cjs +13 -9
- package/com/test/build.f.cjs +1 -1
- package/commonjs/build/module.f.cjs +1 -1
- package/commonjs/build/test.f.cjs +2 -1
- package/commonjs/module/module.f.cjs +1 -1
- package/commonjs/path/module.f.cjs +5 -5
- package/dev/test.mjs +1 -1
- package/doc/predefined.md +2 -2
- package/fsc/test.f.cjs +1 -1
- package/json/module.f.cjs +4 -4
- package/package.json +1 -1
- package/text/README.md +2 -2
- package/text/utf8/module.f.cjs +15 -15
- package/types/array/module.f.cjs +9 -6
- package/types/btree/find/module.f.cjs +3 -3
- package/types/btree/module.f.cjs +2 -2
- package/types/btree/remove/module.f.cjs +11 -11
- package/types/btree/remove/test.f.cjs +52 -52
- package/types/btree/set/module.f.cjs +6 -6
- package/types/btree/test.f.cjs +2 -2
- package/types/btree/types/module.f.cjs +1 -1
- package/types/byte_set/module.f.cjs +1 -1
- package/types/list/module.f.cjs +37 -38
- package/types/list/test.f.cjs +9 -9
- package/types/map/module.f.cjs +6 -6
- package/types/map/test.f.cjs +9 -9
- package/types/nullable/module.f.cjs +17 -0
- package/types/{option → nullable}/test.f.cjs +2 -2
- package/types/number/module.f.cjs +2 -2
- package/types/number/test.f.cjs +1 -1
- package/types/range_map/module.f.cjs +6 -6
- package/types/range_map/test.f.cjs +2 -2
- package/types/sorted_list/module.f.cjs +11 -12
- package/types/sorted_list/test.f.cjs +2 -2
- package/types/sorted_set/module.f.cjs +3 -3
- package/types/sorted_set/test.f.cjs +0 -1
- package/types/string_set/module.f.cjs +2 -2
- package/types/string_set/test.f.cjs +3 -3
- package/types/option/module.f.cjs +0 -17
package/com/cpp/module.f.cjs
CHANGED
|
@@ -66,8 +66,7 @@ const cpp = name => lib => {
|
|
|
66
66
|
if (typeof (t) === 'string') { return baseType(t) }
|
|
67
67
|
if (t.length === 2) { return `${type(t[1])} const*` }
|
|
68
68
|
const [id] = t
|
|
69
|
-
|
|
70
|
-
return id
|
|
69
|
+
return 'interface' in lib[id] ? i(id) : id
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
const type = objectType(comRef)
|
package/com/cpp/test.f.cjs
CHANGED
package/com/cpp/testlib.f.cjs
CHANGED
|
@@ -3,4 +3,4 @@ const { flat } = require("../../text/module.f.cjs")
|
|
|
3
3
|
const library = require('../types/testlib.f.cjs')
|
|
4
4
|
const { cpp } = require('./module.f.cjs')
|
|
5
5
|
|
|
6
|
-
module.exports = join('\n')(flat(' ')(cpp('My')(library)))
|
|
6
|
+
module.exports = () => join('\n')(flat(' ')(cpp('My')(library)))
|
package/com/rust/module.f.cjs
CHANGED
|
@@ -51,22 +51,26 @@ const this_ = ['this: &Object']
|
|
|
51
51
|
const rustType = n => `pub type ${n} = nanocom::${n}<Interface>;`
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* @
|
|
55
|
-
*
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
* @template T
|
|
55
|
+
* @typedef {T|{}} OptionalProperty
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/** @typedef {{readonly where: readonly string[]}} Where */
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {OptionalProperty<Where> & {readonly content: text.Block}} WhereContent
|
|
58
62
|
*/
|
|
59
63
|
|
|
60
64
|
/** @type {(h: string) => (wh: WhereContent) => text.Block} */
|
|
61
|
-
const whereContent = h =>
|
|
62
|
-
const w =
|
|
65
|
+
const whereContent = h => wh => {
|
|
66
|
+
const w = 'where' in wh ? [
|
|
63
67
|
h,
|
|
64
68
|
`where`,
|
|
65
|
-
mapComma(where),
|
|
69
|
+
mapComma(wh.where),
|
|
66
70
|
'{'
|
|
67
|
-
]
|
|
71
|
+
]: [`${h} {`]
|
|
68
72
|
const x = [
|
|
69
|
-
content,
|
|
73
|
+
wh.content,
|
|
70
74
|
'}',
|
|
71
75
|
]
|
|
72
76
|
return flat([w, x])
|
package/com/test/build.f.cjs
CHANGED
|
@@ -86,7 +86,7 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
86
86
|
// check moduleMap
|
|
87
87
|
{
|
|
88
88
|
const m = moduleMapInterface.at(moduleIdStr)(moduleMap)
|
|
89
|
-
if (m !==
|
|
89
|
+
if (m !== null) { return [m, moduleMap] }
|
|
90
90
|
}
|
|
91
91
|
// check package
|
|
92
92
|
const p = packageGet(moduleId.package)
|
|
@@ -73,11 +73,12 @@ const getOrBuild = _.getOrBuild
|
|
|
73
73
|
module.exports = () => {
|
|
74
74
|
let [r, m] = getOrBuild({ package: '', path: ['index.js'] })(map.empty)
|
|
75
75
|
{
|
|
76
|
+
if (r === null) { throw 'r === null' }
|
|
76
77
|
const x = JSON.stringify(r)
|
|
77
78
|
if (x !==
|
|
78
79
|
'["ok",{"exports":":index.js","requireMap":{"./a/":"/a/index.js","./b":"/b.js","x/r":"/node_modules/x/r.js"}}]'
|
|
79
80
|
) {
|
|
80
|
-
throw x
|
|
81
|
+
throw `0:${x}`
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
{
|
|
@@ -3,7 +3,7 @@ const object = require('../../types/object/module.f.cjs')
|
|
|
3
3
|
/**
|
|
4
4
|
* @template M
|
|
5
5
|
* @typedef {{
|
|
6
|
-
* readonly at: (moduleId: string) => (moduleMap: M) => State |
|
|
6
|
+
* readonly at: (moduleId: string) => (moduleMap: M) => State | null
|
|
7
7
|
* readonly setReplace: (moduleId: string) => (moduleState: State) => (moduleMap: M) => M
|
|
8
8
|
* }} MapInterface
|
|
9
9
|
*/
|
|
@@ -27,7 +27,7 @@ const normItemsOp = first => prior => {
|
|
|
27
27
|
case '': case '.': { return prior }
|
|
28
28
|
case '..': {
|
|
29
29
|
const result = next(tail)
|
|
30
|
-
if (result ===
|
|
30
|
+
if (result === null) { return null }
|
|
31
31
|
return [result.tail]
|
|
32
32
|
}
|
|
33
33
|
default: {
|
|
@@ -80,10 +80,10 @@ const variants = prior => () => {
|
|
|
80
80
|
return { first: n, tail: variants(n) }
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/** @type {(d: (local: string) => string|null) => (p: IdPath) => IdPath|
|
|
83
|
+
/** @type {(d: (local: string) => string|null) => (p: IdPath) => IdPath|null} */
|
|
84
84
|
const mapDependency = d => ([external, internal]) => {
|
|
85
85
|
const id = d(external)
|
|
86
|
-
return id === null ?
|
|
86
|
+
return id === null ? null : [id, internal]
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -152,10 +152,10 @@ const parseAndFind = packageGet => moduleId => path => {
|
|
|
152
152
|
if (p === null) { return null }
|
|
153
153
|
const pack = packageGet(p.package)
|
|
154
154
|
if (pack === null) { return null }
|
|
155
|
-
/** @type {(file: string) => FoundResult |
|
|
155
|
+
/** @type {(file: string) => FoundResult | null } */
|
|
156
156
|
const tryFile = file => {
|
|
157
157
|
const source = pack.file(file)
|
|
158
|
-
return source === null ?
|
|
158
|
+
return source === null ? null : { id: { package: p.package, path: file.split('/') }, source }
|
|
159
159
|
}
|
|
160
160
|
const file = p.items.join('/')
|
|
161
161
|
const indexJs = join('/')(concat(p.items)(['index.js']))
|
package/dev/test.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { loadModuleMap } from './module.mjs'
|
|
|
4
4
|
const main = async() => {
|
|
5
5
|
const moduleMap = await loadModuleMap()
|
|
6
6
|
|
|
7
|
-
/** @type {(s: string) => (_:
|
|
7
|
+
/** @type {(s: string) => <T>(_: T) => T} */
|
|
8
8
|
const log = s => state => {
|
|
9
9
|
console.log(s)
|
|
10
10
|
return state
|
package/doc/predefined.md
CHANGED
|
@@ -8,7 +8,7 @@ Global objects. Global objects can't be assigned to something `const r = Object`
|
|
|
8
8
|
|
|
9
9
|
- [x] `Infinity`
|
|
10
10
|
- [x] `NaN`
|
|
11
|
-
- [
|
|
11
|
+
- [ ] `undefined`
|
|
12
12
|
- [ ] `globalThis`
|
|
13
13
|
|
|
14
14
|
### Function properties
|
|
@@ -120,7 +120,7 @@ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
|
|
|
120
120
|
|
|
121
121
|
- [ ] ! `constructor`. The property can create a new function. For example
|
|
122
122
|
```js
|
|
123
|
-
const f = (() =>
|
|
123
|
+
const f = (() => null).constructor('a', 'return a * a')
|
|
124
124
|
```
|
|
125
125
|
- [ ] deprecated `__proto__`
|
|
126
126
|
- [ ] ! deprecated `__defineGetter__`. The property can mutate an object.
|
package/fsc/test.f.cjs
CHANGED
package/json/module.f.cjs
CHANGED
|
@@ -17,13 +17,13 @@ const { entries } = Object
|
|
|
17
17
|
|
|
18
18
|
/** @typedef {Object|boolean|string|number|null|Array} Unknown */
|
|
19
19
|
|
|
20
|
-
/** @type {(value: Unknown) => (path: list.List<string>) => (src: Unknown
|
|
20
|
+
/** @type {(value: Unknown) => (path: list.List<string>) => (src: Unknown) => Unknown} */
|
|
21
21
|
const setProperty = value => {
|
|
22
|
-
/** @type {(path: list.List<string>) => (src: Unknown
|
|
22
|
+
/** @type {(path: list.List<string>) => (src: Unknown) => Unknown} */
|
|
23
23
|
const f = path => src => {
|
|
24
24
|
const result = next(path)
|
|
25
|
-
if (result ===
|
|
26
|
-
const srcObject = (src ===
|
|
25
|
+
if (result === null) { return value }
|
|
26
|
+
const srcObject = (src === null || typeof src !== 'object' || src instanceof Array) ? {} : src
|
|
27
27
|
const { first, tail } = result
|
|
28
28
|
return { ...srcObject, [first]: f(tail)(at(first)(srcObject)) }
|
|
29
29
|
}
|
package/package.json
CHANGED
package/text/README.md
CHANGED
|
@@ -37,7 +37,7 @@ Total error states:
|
|
|
37
37
|
### utf8/module.f.cjs
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
|
-
/** @type {(input: List<u8|
|
|
40
|
+
/** @type {(input: List<u8|null>) => List<i32>} */
|
|
41
41
|
const toCodePointList
|
|
42
42
|
|
|
43
43
|
/** @type {(input: List<i32>) => List<u8>} */
|
|
@@ -72,7 +72,7 @@ Total error states: 11 bit
|
|
|
72
72
|
### utf16/module.f.cjs
|
|
73
73
|
|
|
74
74
|
```js
|
|
75
|
-
/** @type {(input: List<u16|
|
|
75
|
+
/** @type {(input: List<u16|null>) => List<i32>} */
|
|
76
76
|
const toCodePointList
|
|
77
77
|
|
|
78
78
|
/** @type {(input: List<i32>) => List<u16>} */
|
package/text/utf8/module.f.cjs
CHANGED
|
@@ -3,11 +3,11 @@ const operator = require('../../types/function/operator/module.f.cjs')
|
|
|
3
3
|
const array = require('../../types/array/module.f.cjs')
|
|
4
4
|
const { flatMap, flat, stateScan } = list
|
|
5
5
|
|
|
6
|
-
/** @typedef {u8|
|
|
6
|
+
/** @typedef {u8|null} ByteOrEof */
|
|
7
7
|
|
|
8
8
|
/** @typedef {array.Array1<number>|array.Array2<number>|array.Array3<number>} Utf8NonEmptyState */
|
|
9
9
|
|
|
10
|
-
/** @typedef {
|
|
10
|
+
/** @typedef {null|Utf8NonEmptyState} Utf8State */
|
|
11
11
|
|
|
12
12
|
/** @typedef {number} u8 */
|
|
13
13
|
|
|
@@ -50,45 +50,45 @@ const utf8ByteToCodePointOp = state => byte => {
|
|
|
50
50
|
if (byte < 0x00 || byte > 0xff) {
|
|
51
51
|
return [[errorMask], state]
|
|
52
52
|
}
|
|
53
|
-
if (state
|
|
54
|
-
if (byte < 0b1000_0000) { return [[byte],
|
|
53
|
+
if (state === null) {
|
|
54
|
+
if (byte < 0b1000_0000) { return [[byte], null] }
|
|
55
55
|
if (byte >= 0b1100_0010 && byte <= 0b1111_0100) { return [[], [byte]] }
|
|
56
|
-
return [[byte | errorMask],
|
|
56
|
+
return [[byte | errorMask], null]
|
|
57
57
|
}
|
|
58
58
|
if (byte >= 0b1000_0000 && byte < 0b1100_0000) {
|
|
59
59
|
switch (state.length) {
|
|
60
60
|
case 1:
|
|
61
|
-
if (state[0] < 0b1110_0000) { return [[((state[0] & 0b0001_1111) << 6) + (byte & 0b0011_1111)],
|
|
61
|
+
if (state[0] < 0b1110_0000) { return [[((state[0] & 0b0001_1111) << 6) + (byte & 0b0011_1111)], null] }
|
|
62
62
|
if (state[0] < 0b1111_1000) { return [[], [state[0], byte]] }
|
|
63
63
|
break
|
|
64
64
|
case 2:
|
|
65
|
-
if (state[0] < 0b1111_0000) { return [[((state[0] & 0b0000_1111) << 12) + ((state[1] & 0b0011_1111) << 6) + (byte & 0b0011_1111)],
|
|
65
|
+
if (state[0] < 0b1111_0000) { return [[((state[0] & 0b0000_1111) << 12) + ((state[1] & 0b0011_1111) << 6) + (byte & 0b0011_1111)], null] }
|
|
66
66
|
if (state[0] < 0b1111_1000) { return [[], [state[0], state[1], byte]] }
|
|
67
67
|
break
|
|
68
68
|
case 3:
|
|
69
|
-
return [[((state[0] & 0b0000_0111) << 18) + ((state[1] & 0b0011_1111) << 12) + ((state[2] & 0b0011_1111) << 6) + (byte & 0b0011_1111)],
|
|
69
|
+
return [[((state[0] & 0b0000_0111) << 18) + ((state[1] & 0b0011_1111) << 12) + ((state[2] & 0b0011_1111) << 6) + (byte & 0b0011_1111)], null]
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
const error = utf8StateToError(state)
|
|
73
|
-
if (byte < 0b1000_0000) { return [[error, byte],
|
|
73
|
+
if (byte < 0b1000_0000) { return [[error, byte], null] }
|
|
74
74
|
if (byte >= 0b1100_0010 && byte <= 0b1111_0100) { return [[error], [byte]] }
|
|
75
|
-
return [[error, byte | errorMask],
|
|
75
|
+
return [[error, byte | errorMask], null]
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/** @type {(state: Utf8State) => readonly[list.List<i32>, Utf8State]} */
|
|
79
79
|
const utf8EofToCodePointOp = state => {
|
|
80
|
-
if (state ===
|
|
81
|
-
return [[utf8StateToError(state)],
|
|
80
|
+
if (state === null) { return [null, null] }
|
|
81
|
+
return [[utf8StateToError(state)], null]
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/** @type {operator.StateScan<ByteOrEof, Utf8State, list.List<i32>>} */
|
|
85
|
-
const utf8ByteOrEofToCodePointOp = state => input => input ===
|
|
85
|
+
const utf8ByteOrEofToCodePointOp = state => input => input === null ? utf8EofToCodePointOp(state) : utf8ByteToCodePointOp(state)(input)
|
|
86
86
|
|
|
87
87
|
/** @type {list.List<ByteOrEof>} */
|
|
88
|
-
const eofList = [
|
|
88
|
+
const eofList = [null]
|
|
89
89
|
|
|
90
90
|
/** @type {(input: list.List<u8>) => list.List<i32>} */
|
|
91
|
-
const toCodePointList = input => flat(stateScan(utf8ByteOrEofToCodePointOp)(
|
|
91
|
+
const toCodePointList = input => flat(stateScan(utf8ByteOrEofToCodePointOp)(null)(flat([input, eofList])))
|
|
92
92
|
|
|
93
93
|
module.exports = {
|
|
94
94
|
/** @readonly */
|
package/types/array/module.f.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const option = require('../
|
|
1
|
+
const option = require('../nullable/module.f.cjs')
|
|
2
2
|
const { map } = option
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -84,14 +84,17 @@ const uncheckTail = a => a.slice(1)
|
|
|
84
84
|
/** @type {<T>(_: readonly T[]) => readonly T[]} */
|
|
85
85
|
const uncheckHead = a => a.slice(0, -1)
|
|
86
86
|
|
|
87
|
-
/** @type {<T>(a: T
|
|
88
|
-
const
|
|
87
|
+
/** @type {(index: number) => <T>(a: readonly T[]) => T|null} */
|
|
88
|
+
const unsafeAt = i => a => {
|
|
89
|
+
const r = a[i]
|
|
90
|
+
return r === void 0 ? null : r
|
|
91
|
+
}
|
|
89
92
|
|
|
90
93
|
/** @type {<T>(_: readonly T[]) => T|null} */
|
|
91
|
-
const first =
|
|
94
|
+
const first = unsafeAt(0)
|
|
92
95
|
|
|
93
96
|
/** @type {<T>(_: readonly T[]) => T|null} */
|
|
94
|
-
const last = a =>
|
|
97
|
+
const last = a => unsafeAt(a.length - 1)(a)
|
|
95
98
|
|
|
96
99
|
/** @type {<T>(_: readonly T[]) => readonly T[] | null} */
|
|
97
100
|
const tail = a => a.length === 0 ? null : uncheckTail(a)
|
|
@@ -101,7 +104,7 @@ const splitFirst = a => {
|
|
|
101
104
|
/** @typedef {typeof a[0]} T*/
|
|
102
105
|
/** @type {(_: T) => readonly[T, readonly T[]]} */
|
|
103
106
|
const split = first => [first, uncheckTail(a)]
|
|
104
|
-
return
|
|
107
|
+
return map(split)(first(a))
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
/** @type {<T>(_: readonly T[]) => readonly T[]|null} */
|
|
@@ -94,7 +94,7 @@ const find = c => {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
return f(
|
|
97
|
+
return f(null)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/** @type {<T>(first: First<T>) => boolean} */
|
|
@@ -105,7 +105,7 @@ const isFound = ([i]) => {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
/** @type {<T>(first: First<T>) => T |
|
|
108
|
+
/** @type {<T>(first: First<T>) => T | null} */
|
|
109
109
|
const value = ([i, r]) => {
|
|
110
110
|
switch (i) {
|
|
111
111
|
case 1: {
|
|
@@ -118,7 +118,7 @@ const value = ([i, r]) => {
|
|
|
118
118
|
return r.length === 2 ? r[1] : r[3]
|
|
119
119
|
}
|
|
120
120
|
default: {
|
|
121
|
-
return
|
|
121
|
+
return null
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
}
|
package/types/btree/module.f.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const list = require('../list/module.f.cjs')
|
|
2
2
|
const { flat } = list
|
|
3
|
-
const { map } = require('../
|
|
3
|
+
const { map } = require('../nullable/module.f.cjs')
|
|
4
4
|
const _ = require('./types/module.f.cjs')
|
|
5
5
|
|
|
6
6
|
/** @type {<T>(node: _.Node<T>) => list.Thunk<T>} */
|
|
@@ -31,7 +31,7 @@ const values = map(nodeValues)
|
|
|
31
31
|
|
|
32
32
|
module.exports = {
|
|
33
33
|
/** @readonly */
|
|
34
|
-
empty:
|
|
34
|
+
empty: null,
|
|
35
35
|
/** @readonly */
|
|
36
36
|
find: require('./find/module.f.cjs'),
|
|
37
37
|
/** @readonly */
|
|
@@ -4,11 +4,11 @@ const find = require('../find/module.f.cjs')
|
|
|
4
4
|
const list = require('../../list/module.f.cjs')
|
|
5
5
|
const { fold, concat, next } = list
|
|
6
6
|
const array = require('../../array/module.f.cjs')
|
|
7
|
-
const { map } = require('../../
|
|
7
|
+
const { map } = require('../../nullable/module.f.cjs')
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @template T
|
|
11
|
-
* @typedef {
|
|
11
|
+
* @typedef {null | _.Leaf1<T>} Leaf01
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -22,7 +22,7 @@ const { map } = require('../../option/module.f.cjs')
|
|
|
22
22
|
/** @type {<T>(tail: find.Path<T>) => (n: _.Node<T>) => readonly[T, RemovePath<T>]} */
|
|
23
23
|
const path = tail => n => {
|
|
24
24
|
switch (n.length) {
|
|
25
|
-
case 1: { return [n[0], { first:
|
|
25
|
+
case 1: { return [n[0], { first: null, tail }] }
|
|
26
26
|
case 2: { return [n[0], { first: [n[1]], tail }] }
|
|
27
27
|
case 3: { return path({ first: [0, n], tail })(n[0]) }
|
|
28
28
|
case 5: { return path({ first: [0, n], tail })(n[0]) }
|
|
@@ -65,7 +65,7 @@ const reduceValue2 = a => n => {
|
|
|
65
65
|
/** @type {<T>(a: Leaf01<T>) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>} */
|
|
66
66
|
const initValue0 = a => n => {
|
|
67
67
|
const [, v1, n2] = n
|
|
68
|
-
if (a ===
|
|
68
|
+
if (a === null) {
|
|
69
69
|
switch (n2.length) {
|
|
70
70
|
case 1: { return [[v1, ...n2]] }
|
|
71
71
|
case 2: { return [[v1], n2[0], [n2[1]]] }
|
|
@@ -79,7 +79,7 @@ const initValue0 = a => n => {
|
|
|
79
79
|
/** @type {<T>(a: Leaf01<T>) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>} */
|
|
80
80
|
const initValue1 = a => n => {
|
|
81
81
|
const [n0, v1] = n
|
|
82
|
-
if (a ===
|
|
82
|
+
if (a === null) {
|
|
83
83
|
switch (n0.length) {
|
|
84
84
|
case 1: { return [[...n0, v1]] }
|
|
85
85
|
case 2: { return [[n0[0]], n0[1], [v1]] }
|
|
@@ -118,19 +118,19 @@ const initReduce = reduceX([initValue0, initValue1])
|
|
|
118
118
|
/** @type {<T>(c: cmp.Compare<T>) => (node: _.Node<T>) => _.Tree<T>} */
|
|
119
119
|
const nodeRemove = c => node => {
|
|
120
120
|
/** @typedef {typeof c extends cmp.Compare<infer T> ? T : never} T */
|
|
121
|
-
/** @type {() =>
|
|
121
|
+
/** @type {() => null | RemovePath<T>} */
|
|
122
122
|
const f = () => {
|
|
123
123
|
const { first, tail } = find.find(c)(node)
|
|
124
124
|
/** @type {(n: _.Node<T>) => (f: (v: T) => find.PathItem<T>) => RemovePath<T>} */
|
|
125
125
|
const branch = n => f => {
|
|
126
|
-
const [v, p] = path(/** @type {find.Path<T>} */(
|
|
126
|
+
const [v, p] = path(/** @type {find.Path<T>} */(null))(n)
|
|
127
127
|
return { first: p.first, tail: concat(p.tail)({ first: f(v), tail }) }
|
|
128
128
|
}
|
|
129
129
|
const [i, n] = first
|
|
130
130
|
switch (i) {
|
|
131
131
|
case 1: {
|
|
132
132
|
switch (n.length) {
|
|
133
|
-
case 1: { return { first:
|
|
133
|
+
case 1: { return { first: null, tail } }
|
|
134
134
|
case 2: { return { first: [n[1]], tail } }
|
|
135
135
|
case 3: { return branch(n[2])(v => [2, [n[0], v, n[2]]]) }
|
|
136
136
|
case 5: { return branch(n[2])(v => [2, [n[0], v, n[2], n[3], n[4]]]) }
|
|
@@ -142,14 +142,14 @@ const nodeRemove = c => node => {
|
|
|
142
142
|
case 5: { return branch(n[4])(v => [4, [n[0], n[1], n[2], v, n[4]]]) }
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
default: { return
|
|
145
|
+
default: { return null }
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
const r = f()
|
|
149
|
-
if (r ===
|
|
149
|
+
if (r === null) { return node }
|
|
150
150
|
const { first, tail } = r
|
|
151
151
|
const tailR = next(tail)
|
|
152
|
-
if (tailR ===
|
|
152
|
+
if (tailR === null) { return first }
|
|
153
153
|
const { first: tf, tail: tt } = tailR
|
|
154
154
|
const result = reduce(initReduce(tf)(first))(tt)
|
|
155
155
|
return result.length === 1 ? result[0] : result
|