functionalscript 0.0.398 → 0.0.399
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/commonjs/build/module.f.cjs +3 -3
- package/commonjs/module/module.f.cjs +1 -1
- package/package.json +1 -1
- package/types/btree/find/test.f.cjs +1 -1
- package/types/btree/remove/test.f.cjs +1 -1
- package/types/btree/set/module.f.cjs +14 -12
- package/types/btree/set/test.f.cjs +1 -1
- package/types/btree/test.f.cjs +1 -1
- package/types/map/module.f.cjs +14 -5
- package/types/map/test.f.cjs +12 -9
- package/types/string_set/module.f.cjs +1 -1
|
@@ -3,7 +3,7 @@ const module_ = require('../module/module.f.cjs')
|
|
|
3
3
|
const { idToString, dir } = module_
|
|
4
4
|
const function_ = require('../module/function/module.f.cjs')
|
|
5
5
|
const map = require('../../types/map/module.f.cjs')
|
|
6
|
-
const {
|
|
6
|
+
const { setReplace } = map
|
|
7
7
|
const object = require('../../types/object/module.f.cjs')
|
|
8
8
|
const { fromMap } = object
|
|
9
9
|
const path = require('../path/module.f.cjs')
|
|
@@ -62,11 +62,11 @@ const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
62
62
|
const rIdStr = idToString(r.id)
|
|
63
63
|
if (setContains(rIdStr)(buildSet1)) { return error('circular reference') }
|
|
64
64
|
const [state, m1] = build(buildSet1)(r.id)(r.source)(m)
|
|
65
|
-
return [state[0] === 'error' ? state : ['ok', state[1].exports], [
|
|
65
|
+
return [state[0] === 'error' ? state : ['ok', state[1].exports], [setReplace(p)(rIdStr)(requireMap), m1]]
|
|
66
66
|
}
|
|
67
67
|
return source => moduleMap => {
|
|
68
68
|
/** @type {(s: module_.State) => (m: M) => Result<M>} */
|
|
69
|
-
const set = s => m => [s, moduleMapInterface.
|
|
69
|
+
const set = s => m => [s, moduleMapInterface.setReplace(moduleIdStr)(s)(m)]
|
|
70
70
|
/** @type {(e: module_.Error) => (m: M) => Result<M>} */
|
|
71
71
|
const error = e => set(['error', e])
|
|
72
72
|
// check compilation
|
|
@@ -4,7 +4,7 @@ const object = require('../../types/object/module.f.cjs')
|
|
|
4
4
|
* @template M
|
|
5
5
|
* @typedef {{
|
|
6
6
|
* readonly at: (moduleId: string) => (moduleMap: M) => State | undefined
|
|
7
|
-
* readonly
|
|
7
|
+
* readonly setReplace: (moduleId: string) => (moduleState: State) => (moduleMap: M) => M
|
|
8
8
|
* }} MapInterface
|
|
9
9
|
*/
|
|
10
10
|
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ const s = require('../set/module.f.cjs')
|
|
|
9
9
|
const jsonStr = json.stringify(sort)
|
|
10
10
|
|
|
11
11
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
12
|
-
const set = node => value => s.set(stringCmp(value))(value)(node)
|
|
12
|
+
const set = node => value => s.set(stringCmp(value))(() => value)(node)
|
|
13
13
|
|
|
14
14
|
/** @type {(r: _.Result<json.Unknown>) => string} */
|
|
15
15
|
const str = r => jsonStr(list.toArray(list.map(x => x[0])(r)))
|
|
@@ -6,7 +6,7 @@ const json = require('../../../json/module.f.cjs')
|
|
|
6
6
|
const { sort } = require('../../object/module.f.cjs')
|
|
7
7
|
|
|
8
8
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
9
|
-
const set = node => value => s.set(stringCmp(value))(value)(node)
|
|
9
|
+
const set = node => value => s.set(stringCmp(value))(() => value)(node)
|
|
10
10
|
|
|
11
11
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string> | undefined} */
|
|
12
12
|
const remove = node => value => _.nodeRemove(stringCmp(value))(node)
|
|
@@ -36,16 +36,17 @@ const reduceOp = ([i, x]) => a => {
|
|
|
36
36
|
|
|
37
37
|
const reduceBranch = reduce(reduceOp)
|
|
38
38
|
|
|
39
|
-
/** @type {<T>(c: cmp.Compare<T>) => (
|
|
40
|
-
const nodeSet = c =>
|
|
39
|
+
/** @type {<T>(c: cmp.Compare<T>) => (g: (value?: T) => T) => (node: _.Node<T>) => _.Node<T>} */
|
|
40
|
+
const nodeSet = c => g => node => {
|
|
41
41
|
const { first, tail } = find(c)(node)
|
|
42
42
|
const [i, x] = first;
|
|
43
|
-
/** @typedef {typeof
|
|
43
|
+
/** @typedef {typeof c extends cmp.Compare<infer T> ? T : never} T */
|
|
44
44
|
/** @type {() => Branch1To3<T>} */
|
|
45
45
|
const f = () => {
|
|
46
46
|
switch (i) {
|
|
47
47
|
case 0: {
|
|
48
48
|
// insert
|
|
49
|
+
const value = g()
|
|
49
50
|
switch (x.length) {
|
|
50
51
|
case 1: { return [[value, x[0]]] }
|
|
51
52
|
case 2: { return [[value], x[0], [x[1]]] }
|
|
@@ -54,14 +55,15 @@ const nodeSet = c => value => node => {
|
|
|
54
55
|
case 1: {
|
|
55
56
|
// replace
|
|
56
57
|
switch (x.length) {
|
|
57
|
-
case 1: { return [[
|
|
58
|
-
case 2: { return [[
|
|
59
|
-
case 3: { return [[x[0],
|
|
60
|
-
case 5: { return [[x[0],
|
|
58
|
+
case 1: { return [[g(x[0])]] }
|
|
59
|
+
case 2: { return [[g(x[0]), x[1]]] }
|
|
60
|
+
case 3: { return [[x[0], g(x[1]), x[2]]] }
|
|
61
|
+
case 5: { return [[x[0], g(x[1]), x[2], x[3], x[4]]] }
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
case 2: {
|
|
64
65
|
// insert
|
|
66
|
+
const value = g()
|
|
65
67
|
switch (x.length) {
|
|
66
68
|
case 1: { return [[x[0], value]] }
|
|
67
69
|
case 2: { return [[x[0]], value, [x[1]]] }
|
|
@@ -70,14 +72,14 @@ const nodeSet = c => value => node => {
|
|
|
70
72
|
case 3: {
|
|
71
73
|
// replace
|
|
72
74
|
switch (x.length) {
|
|
73
|
-
case 2: { return [[x[0],
|
|
74
|
-
case 5: { return [[x[0], x[1], x[2],
|
|
75
|
+
case 2: { return [[x[0], g(x[1])]] }
|
|
76
|
+
case 5: { return [[x[0], x[1], x[2], g(x[3]), x[4]]]}
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
case 4: {
|
|
78
80
|
// insert
|
|
79
81
|
const [v0, v1] = x;
|
|
80
|
-
return [[v0], v1, [
|
|
82
|
+
return [[v0], v1, [g()]]
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
}
|
|
@@ -85,8 +87,8 @@ const nodeSet = c => value => node => {
|
|
|
85
87
|
return r.length === 1 ? r[0] : r
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
/** @type {<T>(c: cmp.Compare<T>) => (
|
|
89
|
-
const set = c =>
|
|
90
|
+
/** @type {<T>(c: cmp.Compare<T>) => (f: (value?: T) => T) => (tree: _.Tree<T>) => _.Node<T>} */
|
|
91
|
+
const set = c => f => tree => tree === undefined ? [f()] : nodeSet(c)(f)(tree)
|
|
90
92
|
|
|
91
93
|
module.exports = {
|
|
92
94
|
/** @readonly */
|
|
@@ -5,7 +5,7 @@ const json = require('../../../json/module.f.cjs')
|
|
|
5
5
|
const { sort } = require('../../object/module.f.cjs')
|
|
6
6
|
|
|
7
7
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
8
|
-
const set = node => value => _.set(stringCmp(value))(value)(node)
|
|
8
|
+
const set = node => value => _.set(stringCmp(value))(() => value)(node)
|
|
9
9
|
|
|
10
10
|
const jsonStr = json.stringify(sort)
|
|
11
11
|
|
package/types/btree/test.f.cjs
CHANGED
|
@@ -17,7 +17,7 @@ const jsonStr = json.stringify(sort)
|
|
|
17
17
|
const stringify = sequence => jsonStr(list.toArray(sequence))
|
|
18
18
|
|
|
19
19
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
20
|
-
const set = node => value => s.set(stringCmp(value))(value)(node)
|
|
20
|
+
const set = node => value => s.set(stringCmp(value))(() => value)(node)
|
|
21
21
|
|
|
22
22
|
{
|
|
23
23
|
/** @type {btree.Node<string>} */
|
package/types/map/module.f.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const { stringCmp } = require('../function/compare/module.f.cjs')
|
|
|
8
8
|
const list = require('../list/module.f.cjs')
|
|
9
9
|
const { reduce } = list
|
|
10
10
|
const { remove: btreeRemove } = require('../btree/remove/module.f.cjs')
|
|
11
|
+
const operator = require('../function/operator/module.f.cjs')
|
|
11
12
|
|
|
12
13
|
/** @typedef {compare.Sign} Sign */
|
|
13
14
|
|
|
@@ -36,17 +37,23 @@ const at = name => map => {
|
|
|
36
37
|
return result === undefined ? undefined : result[1]
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
/** @type {<T>(entry: Entry<T>) => (map: Map<T>) => Map<T>} */
|
|
40
|
-
const
|
|
40
|
+
/** @type {<T>(o: operator.Fold<T>) => (entry: Entry<T>) => (map: Map<T>) => Map<T>} */
|
|
41
|
+
const setUpdateEntry = o => entry => btreeSet(keyCmp(entry[0]))(old => old === undefined ? entry : [old[0], o(old[1])(entry[1])])
|
|
42
|
+
|
|
43
|
+
/** @type {<T>(o: operator.Fold<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>} */
|
|
44
|
+
const setUpdate = o => name => value => setUpdateEntry(o)([name, value])
|
|
41
45
|
|
|
42
46
|
/** @type {(name: string) => <T>(value: T) => (map: Map<T>) => Map<T>} */
|
|
43
|
-
const
|
|
47
|
+
const setReplace = name => value => setUpdateEntry(replace)([name, value])
|
|
44
48
|
|
|
45
49
|
/** @type {<T>(map: Map<T>) => list.List<Entry<T>>} */
|
|
46
50
|
const entries = values
|
|
47
51
|
|
|
52
|
+
/** @type {<T>(a: T) => (b: T) => T} */
|
|
53
|
+
const replace = () => b => b
|
|
54
|
+
|
|
48
55
|
/** @type {<T>(entries: list.List<Entry<T>>) => Map<T>} */
|
|
49
|
-
const fromEntries = reduce(
|
|
56
|
+
const fromEntries = reduce(setUpdateEntry(replace))(undefined)
|
|
50
57
|
|
|
51
58
|
/** @type {(name: string) => <T>(map: Map<T>) => Map<T>} */
|
|
52
59
|
const remove = name => btreeRemove(keyCmp(name))
|
|
@@ -57,7 +64,9 @@ module.exports = {
|
|
|
57
64
|
/** @readonly */
|
|
58
65
|
at,
|
|
59
66
|
/** @readonly */
|
|
60
|
-
|
|
67
|
+
setUpdate,
|
|
68
|
+
/** @readonly */
|
|
69
|
+
setReplace,
|
|
61
70
|
/** @readonly */
|
|
62
71
|
entries,
|
|
63
72
|
/** @readonly */
|
package/types/map/test.f.cjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
const { at,
|
|
1
|
+
const { at, setReplace, setUpdate, empty, entries, remove } = require('./module.f.cjs')
|
|
2
2
|
const seq = require('../list/module.f.cjs')
|
|
3
3
|
|
|
4
4
|
{
|
|
5
|
-
let m =
|
|
5
|
+
let m = setReplace('a')(1)(undefined)
|
|
6
6
|
|
|
7
7
|
if (at('a')(m) !== 1) { throw 'error' }
|
|
8
8
|
if (at('b')(m) !== undefined) { throw 'error' }
|
|
9
9
|
|
|
10
|
-
m =
|
|
10
|
+
m = setReplace('b')(2)(m)
|
|
11
11
|
|
|
12
12
|
if (at('a')(m) !== 1) { throw 'error' }
|
|
13
13
|
if (at('b')(m) !== 2) { throw 'error' }
|
|
14
14
|
if (at('c')(m) !== undefined) { throw 'error' }
|
|
15
15
|
|
|
16
|
-
m =
|
|
16
|
+
m = setReplace('z')(3)(m)
|
|
17
17
|
|
|
18
18
|
if (at('a')(m) !== 1) { throw 'error' }
|
|
19
19
|
if (at('b')(m) !== 2) { throw 'error' }
|
|
20
20
|
if (at('z')(m) !== 3) { throw 'error' }
|
|
21
21
|
if (at('')(m) !== undefined) { throw 'error' }
|
|
22
22
|
|
|
23
|
-
m =
|
|
23
|
+
m = setReplace('')(4)(m)
|
|
24
24
|
|
|
25
25
|
if (at('a')(m) !== 1) { throw 'error' }
|
|
26
26
|
if (at('b')(m) !== 2) { throw 'error' }
|
|
@@ -28,7 +28,7 @@ const seq = require('../list/module.f.cjs')
|
|
|
28
28
|
if (at('')(m) !== 4) { throw 'error' }
|
|
29
29
|
if (at('Hello world!')(m) !== undefined) { throw 'error' }
|
|
30
30
|
|
|
31
|
-
m =
|
|
31
|
+
m = setReplace('Hello world!')(42)(m)
|
|
32
32
|
|
|
33
33
|
if (at('a')(m) !== 1) { throw 'error' }
|
|
34
34
|
if (at('b')(m) !== 2) { throw 'error' }
|
|
@@ -40,11 +40,14 @@ const seq = require('../list/module.f.cjs')
|
|
|
40
40
|
// console.log(Array.from(m.entries()))
|
|
41
41
|
m = remove('Hello world!')(m)
|
|
42
42
|
if (at('Hello world!')(m) !== undefined) { throw m }
|
|
43
|
+
|
|
44
|
+
m = setUpdate(a => b => a + b)('a')(43)(m)
|
|
45
|
+
if (at('a')(m) !== 44) { throw 'error' }
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
{
|
|
46
|
-
let m =
|
|
47
|
-
m =
|
|
49
|
+
let m = setReplace('x')(12)(undefined)
|
|
50
|
+
m = setReplace('y')(44)(m)
|
|
48
51
|
if (at('x')(m) !== 12) { throw 'error' }
|
|
49
52
|
if (at('y')(m) !== 44) { throw 'error' }
|
|
50
53
|
if (at('a')(m) !== undefined) { throw 'error' }
|
|
@@ -56,7 +59,7 @@ const seq = require('../list/module.f.cjs')
|
|
|
56
59
|
/** @type {import('./module.f.cjs').Map<number>} */
|
|
57
60
|
let m = empty
|
|
58
61
|
for (let i = 0; i < 100_000; ++i) {
|
|
59
|
-
m =
|
|
62
|
+
m = setReplace((i * i).toString())(i)(m)
|
|
60
63
|
/*
|
|
61
64
|
console.log()
|
|
62
65
|
console.log(`# ${i}`)
|
|
@@ -18,7 +18,7 @@ const { compose } = require('../function/module.f.cjs')
|
|
|
18
18
|
const contains = value => s => s !== undefined && isFound(find(stringCmp(value))(s).first)
|
|
19
19
|
|
|
20
20
|
/** @type {(value: string) => (s: StringSet) => StringSet} */
|
|
21
|
-
const set = value => btreeSet(stringCmp(value))(value)
|
|
21
|
+
const set = value => btreeSet(stringCmp(value))(() => value)
|
|
22
22
|
|
|
23
23
|
const fromValues = reduce(set)(undefined)
|
|
24
24
|
|