functionalscript 0.0.198 → 0.0.203
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/btree/index.js +26 -26
- package/btree/test.js +6 -5
- package/map/index.js +5 -4
- package/module-manager/README.md +30 -0
- package/module-manager/node/test.js +1 -1
- package/module-manager/test.js +4 -4
- package/package.json +1 -1
- package/test.js +48 -0
package/btree/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const cmp = require('../cmp')
|
|
2
|
+
const { index3, index5 } = cmp
|
|
2
3
|
const seq = require('../sequence')
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -8,29 +9,29 @@ const seq = require('../sequence')
|
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @template T
|
|
11
|
-
* @typedef {
|
|
12
|
+
* @typedef {cmp.Cmp<T>} Cmp
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @template T
|
|
16
|
-
* @typedef {
|
|
17
|
+
* @typedef {readonly[T]} Array1
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @template T
|
|
21
|
-
* @typedef {
|
|
22
|
+
* @typedef {readonly[T,T]} Array2
|
|
22
23
|
*/
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* @template T
|
|
26
|
-
* @typedef {
|
|
27
|
+
* @typedef {readonly[T,T,T]} Array3
|
|
27
28
|
*/
|
|
28
29
|
|
|
29
|
-
/** @typedef {
|
|
30
|
+
/** @typedef {0|1} Index2 */
|
|
30
31
|
|
|
31
|
-
/** @typedef {
|
|
32
|
+
/** @typedef {0|1|2} Index3 */
|
|
32
33
|
|
|
33
|
-
/** @typedef {
|
|
34
|
+
/** @typedef {0|1|2|3|4} Index5 */
|
|
34
35
|
|
|
35
36
|
//
|
|
36
37
|
|
|
@@ -59,14 +60,11 @@ const seq = require('../sequence')
|
|
|
59
60
|
* @typedef { Leaf1<T> | Leaf2<T> | Branch3<T> | Branch5<T>} Node
|
|
60
61
|
*/
|
|
61
62
|
|
|
62
|
-
/** @typedef {
|
|
63
|
+
/** @typedef {readonly['done']} NotFoundDone */
|
|
63
64
|
|
|
64
65
|
/**
|
|
65
66
|
* @template T
|
|
66
|
-
* @typedef {
|
|
67
|
-
* readonly done: true
|
|
68
|
-
* readonly value: T
|
|
69
|
-
* }} FoundDone
|
|
67
|
+
* @typedef {readonly['done', T]} FoundDone
|
|
70
68
|
*/
|
|
71
69
|
|
|
72
70
|
/**
|
|
@@ -76,12 +74,12 @@ const seq = require('../sequence')
|
|
|
76
74
|
|
|
77
75
|
/**
|
|
78
76
|
* @template T
|
|
79
|
-
* @typedef {
|
|
77
|
+
* @typedef {readonly['replace', Node<T>]} Replace
|
|
80
78
|
*/
|
|
81
79
|
|
|
82
80
|
/**
|
|
83
81
|
* @template T
|
|
84
|
-
* @typedef {
|
|
82
|
+
* @typedef {readonly['overflow', Branch3<T>]} Overflow
|
|
85
83
|
*/
|
|
86
84
|
|
|
87
85
|
/**
|
|
@@ -137,9 +135,11 @@ const split = ([n0, v1, n2, v3, n4, v5, n6]) => [[n0, v1, n2], v3, [n4, v5, n6]]
|
|
|
137
135
|
* Result<T>}
|
|
138
136
|
*/
|
|
139
137
|
const merge = overflow => replace => result => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
switch (result[0]) {
|
|
139
|
+
case 'done': { return result }
|
|
140
|
+
case 'replace': { return ['replace', replace(result[1])] }
|
|
141
|
+
default: { return overflow(result[1]) }
|
|
142
|
+
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
/**
|
|
@@ -148,7 +148,7 @@ const merge = overflow => replace => result => {
|
|
|
148
148
|
* (result: Result<T>) =>
|
|
149
149
|
* Result<T>}
|
|
150
150
|
*/
|
|
151
|
-
const merge2 = overflow => merge(o =>
|
|
151
|
+
const merge2 = overflow => merge(o => ['replace', overflow(o)])
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
154
|
* @type {<T>(overflow: (o: Branch3<T>) => Branch7<T>) =>
|
|
@@ -156,7 +156,7 @@ const merge2 = overflow => merge(o => ({ replace: overflow(o) }))
|
|
|
156
156
|
* (result: Result<T>) =>
|
|
157
157
|
* Result<T>}
|
|
158
158
|
*/
|
|
159
|
-
const merge3 = overflow => merge(o =>
|
|
159
|
+
const merge3 = overflow => merge(o => ['overflow', split(overflow(o))])
|
|
160
160
|
|
|
161
161
|
/** @type {(visitor: Visitor) => <T>(cmp: Cmp<T>) => (init: Lazy<T>) => (node: Node<T>) => Result<T>} */
|
|
162
162
|
const visit = ({ found, notFound }) => cmp => {
|
|
@@ -233,7 +233,7 @@ const visit = ({ found, notFound }) => cmp => {
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
/** @type { <T>(_: T) => Done<T> } */
|
|
236
|
-
const found = value =>
|
|
236
|
+
const found = value => ['done', value]
|
|
237
237
|
|
|
238
238
|
/** @type {Found} */
|
|
239
239
|
const foundGet = {
|
|
@@ -245,7 +245,7 @@ const foundGet = {
|
|
|
245
245
|
branch5_right: () => ([, , , value]) => found(value),
|
|
246
246
|
}
|
|
247
247
|
/** @type { () => () => NotFoundDone } */
|
|
248
|
-
const notFound = () => () =>
|
|
248
|
+
const notFound = () => () => ['done']
|
|
249
249
|
|
|
250
250
|
/** @type {NotFound} */
|
|
251
251
|
const notFoundGet = {
|
|
@@ -257,7 +257,7 @@ const notFoundGet = {
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
/** @type { <T>(_: Node<T>) => Replace<T> } */
|
|
260
|
-
const replace = node =>
|
|
260
|
+
const replace = node => ['replace', node]
|
|
261
261
|
|
|
262
262
|
/** @type {Found} */
|
|
263
263
|
const foundReplace = {
|
|
@@ -270,7 +270,7 @@ const foundReplace = {
|
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
/** @type {<T>(leaf3: Array3<T>) => Result<T>} */
|
|
273
|
-
const overflow = ([v0, v1, v2]) =>
|
|
273
|
+
const overflow = ([v0, v1, v2]) => ['overflow', [[v0], v1, [v2]]]
|
|
274
274
|
|
|
275
275
|
/** @type {NotFound} */
|
|
276
276
|
const notFoundInsert = {
|
|
@@ -339,8 +339,8 @@ module.exports = {
|
|
|
339
339
|
* @type { <T>(cmp: Cmp<T>) => (node: Node<T>) => T|undefined }
|
|
340
340
|
*/
|
|
341
341
|
getVisitor: cmp => node => {
|
|
342
|
-
const
|
|
343
|
-
if ('done'
|
|
342
|
+
const result = visit(getVisitor)(cmp)(() => { throw '' })(node)
|
|
343
|
+
if (result[0] === 'done') { return result[1] }
|
|
344
344
|
return undefined
|
|
345
345
|
},
|
|
346
346
|
/** @readonly */
|
package/btree/test.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
const btree = require('.')
|
|
2
|
-
const { setVisitor, values
|
|
2
|
+
const { setVisitor, values } = btree
|
|
3
3
|
const { cmp } = require('../cmp')
|
|
4
4
|
const list = require('../sequence')
|
|
5
5
|
|
|
6
6
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
7
7
|
const set = node => value => {
|
|
8
8
|
const result = setVisitor(cmp(value))(() => value)(node)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
switch (result[0]) {
|
|
10
|
+
case 'replace': case 'overflow': { return result[1] }
|
|
11
|
+
default: { return node }
|
|
12
|
+
}
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
const test = () => {
|
|
@@ -22,7 +23,7 @@ const test = () => {
|
|
|
22
23
|
//
|
|
23
24
|
{
|
|
24
25
|
/** @type {import('../sequence').Result<string>} */
|
|
25
|
-
let _item = list.next(
|
|
26
|
+
let _item = list.next(values(_map))
|
|
26
27
|
while (_item !== undefined) {
|
|
27
28
|
_item = list.next(_item[1])
|
|
28
29
|
}
|
package/map/index.js
CHANGED
|
@@ -43,10 +43,11 @@ const keyCmp = a => ([b]) => cmp(a)(b)
|
|
|
43
43
|
const create = root => ({
|
|
44
44
|
get: name => option.map(([,value]) => value)(getVisitor(keyCmp(name))(root)),
|
|
45
45
|
set: name => value => {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
const result = setVisitor(keyCmp(name))(() => [name, value])(root)
|
|
47
|
+
switch (result[0]) {
|
|
48
|
+
case 'replace': case 'overflow': { return create(result[1]) }
|
|
49
|
+
default: { throw '' }
|
|
50
|
+
}
|
|
50
51
|
},
|
|
51
52
|
entries: values(root),
|
|
52
53
|
root,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Module Manager
|
|
2
|
+
|
|
3
|
+
## Module Provider
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
/** @typedef {(packageName: string) => PackageMap|Package|undefined} PackageMap */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {{
|
|
10
|
+
* readonly id: string,
|
|
11
|
+
* readonly packages: PackageMap,
|
|
12
|
+
* readonly files: (fileName: string) => string|undefined,
|
|
13
|
+
* }} Package
|
|
14
|
+
*/
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Runner IO
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {(require: Require<T>) => (info: T) => (source: string) => readonly[Result<unknown, Error>, T]} RunnerIo
|
|
22
|
+
*/
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
/**
|
|
27
|
+
* @template T
|
|
28
|
+
* @typedef {(info: T) => (module: string) => readonly[Result<unknown, Error>, T]} Require<T>
|
|
29
|
+
*/
|
|
30
|
+
```
|
package/module-manager/test.js
CHANGED
|
@@ -31,7 +31,7 @@ if (cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('/') !== 'b/d') { thro
|
|
|
31
31
|
const c = {
|
|
32
32
|
dependencies: () => undefined,
|
|
33
33
|
file: path => {
|
|
34
|
-
/** @type {{ [_ in string]?: string}} */
|
|
34
|
+
/** @type {{ readonly [_ in string]?: string}} */
|
|
35
35
|
const f = {
|
|
36
36
|
'index.js': 'b/c ./index.js',
|
|
37
37
|
'x/index.js': 'b/c ./x/index.js',
|
|
@@ -41,11 +41,11 @@ if (cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('/') !== 'b/d') { thro
|
|
|
41
41
|
},
|
|
42
42
|
id: ['c']
|
|
43
43
|
}
|
|
44
|
-
/** @type {{ [_ in string]: i.Package|i.Dependencies}} */
|
|
44
|
+
/** @type {{ readonly [_ in string]: i.Package|i.Dependencies}} */
|
|
45
45
|
const packages = {
|
|
46
46
|
a,
|
|
47
47
|
b: s => {
|
|
48
|
-
/** @type {{ [_ in string]: i.Package|i.Dependencies}} */
|
|
48
|
+
/** @type {{ readonly [_ in string]: i.Package|i.Dependencies}} */
|
|
49
49
|
const p = { c }
|
|
50
50
|
return p[s]
|
|
51
51
|
}
|
|
@@ -54,7 +54,7 @@ if (cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('/') !== 'b/d') { thro
|
|
|
54
54
|
const pack = {
|
|
55
55
|
dependencies: s => packages[s],
|
|
56
56
|
file: path => {
|
|
57
|
-
/** @type {{ [_ in string]?: string}} */
|
|
57
|
+
/** @type {{ readonly [_ in string]?: string}} */
|
|
58
58
|
const f = {
|
|
59
59
|
'index.js': './index.js',
|
|
60
60
|
'index/index.js': './index/index.js',
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -59,3 +59,51 @@ const assert_if = c => { if (c) { throw 'assert_if' } }
|
|
|
59
59
|
v.commit !== '4b14a7a2b11cf53f037931eb7bef240f96dcea64'),
|
|
60
60
|
assert)
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
{
|
|
64
|
+
const c = (()=>{})['constructor']
|
|
65
|
+
const f = c('return 5')
|
|
66
|
+
const result = f()
|
|
67
|
+
if (result !== 5) { throw 'function' }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
{
|
|
71
|
+
/** @type {any} */
|
|
72
|
+
const o = {}
|
|
73
|
+
const c = o['constructor']
|
|
74
|
+
// console.log(c)
|
|
75
|
+
// console.log(c(()=>{}))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
{
|
|
79
|
+
/** @type {any} */
|
|
80
|
+
const o = {
|
|
81
|
+
constructor: undefined
|
|
82
|
+
}
|
|
83
|
+
const c = o['constructor']
|
|
84
|
+
console.log(c)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
/** @type {any} */
|
|
89
|
+
const b = '42'
|
|
90
|
+
const r = Number(b)
|
|
91
|
+
console.log(r)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
{
|
|
95
|
+
/** @type {any} */
|
|
96
|
+
const o = {}
|
|
97
|
+
//const c = o['constructor']
|
|
98
|
+
//const c = o['__proto__']
|
|
99
|
+
//const c = o['__defineGetter__']
|
|
100
|
+
//const c = o['__defineSetter__']
|
|
101
|
+
//const c = o['__lookupGetter__']
|
|
102
|
+
//const c = o['__lookupSetter__']
|
|
103
|
+
//const c = o['hasOwnProperty']
|
|
104
|
+
//const c = o['isPrototypeOf']
|
|
105
|
+
//const c = o['propertyIsEnumerable']
|
|
106
|
+
//const c = o['toString']
|
|
107
|
+
const c = o['valueOf']
|
|
108
|
+
console.log(c)
|
|
109
|
+
}
|