functionalscript 0.0.264 → 0.0.268
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/node.js.yml +0 -1
- package/README.md +8 -2
- package/commonjs/README.md +4 -0
- package/commonjs/build/index.js +99 -0
- package/commonjs/module/function/index.js +21 -0
- package/commonjs/module/index.js +27 -14
- package/commonjs/package/index.js +4 -6
- package/commonjs/path/index.js +12 -7
- package/commonjs/path/test.js +8 -7
- package/io/commonjs/index.js +7 -4
- package/io/commonjs/test.js +1 -1
- package/io/result/index.js +2 -1
- package/package.json +4 -2
- package/types/btree/index.js +38 -41
- package/types/map/index.js +9 -9
- package/types/object/index.js +7 -2
- package/commonjs/run/index.js +0 -17
package/README.md
CHANGED
|
@@ -39,11 +39,11 @@ The prefered way to refence dependencies is to use a GitHub URL. These dependenc
|
|
|
39
39
|
|
|
40
40
|
```json
|
|
41
41
|
{
|
|
42
|
-
...
|
|
42
|
+
// ...
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"third-party-package": "github:exampleorg/thirdpartypackage"
|
|
45
45
|
}
|
|
46
|
-
...
|
|
46
|
+
// ...
|
|
47
47
|
}
|
|
48
48
|
```
|
|
49
49
|
|
|
@@ -82,7 +82,13 @@ module.exports = {
|
|
|
82
82
|
// 1. references
|
|
83
83
|
const first = require('./first.js')
|
|
84
84
|
|
|
85
|
+
// 2. definitions
|
|
85
86
|
const _42plus7 = first.add42(7)
|
|
87
|
+
|
|
88
|
+
// 3. exports
|
|
89
|
+
module.exports = {
|
|
90
|
+
_42plus7,
|
|
91
|
+
}
|
|
86
92
|
```
|
|
87
93
|
|
|
88
94
|
### 2.4. References To Other Modules
|
package/commonjs/README.md
CHANGED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const package_ = require('../package')
|
|
2
|
+
const module_ = require('../module')
|
|
3
|
+
const function_ = require('../module/function')
|
|
4
|
+
const { todo } = require('../../dev')
|
|
5
|
+
const map = require('../../types/map')
|
|
6
|
+
const object = require('../../types/object')
|
|
7
|
+
const list = require('../../types/list')
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @template M
|
|
11
|
+
* @typedef {{
|
|
12
|
+
* readonly pagkageGet: package_.Get
|
|
13
|
+
* readonly moduleMapInterface: module_.MapInterface<M>
|
|
14
|
+
* readonly moduleId: module_.Id
|
|
15
|
+
* readonly moduleMap: M
|
|
16
|
+
* }} Config
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @template M
|
|
21
|
+
* @typedef {readonly[module_.State, M]} Result
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** @type {<M>(moduleMap: M) => Result<M>} */
|
|
25
|
+
const notFound = moduleMap => [['error', ['file not found']], moduleMap]
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @type {(packageGet: package_.Get) =>
|
|
29
|
+
* <M>(moduleMapInterface: module_.MapInterface<M>) =>
|
|
30
|
+
* (compile: function_.Compile) =>
|
|
31
|
+
* (moduleId: module_.Id) =>
|
|
32
|
+
* (moduleMapFirst: M) =>
|
|
33
|
+
* Result<M>
|
|
34
|
+
* }
|
|
35
|
+
*/
|
|
36
|
+
const getOrBuild = packageGet => moduleMapInterface => compile => moduleId => {
|
|
37
|
+
|
|
38
|
+
/** @typedef {typeof moduleMapInterface extends module_.MapInterface<infer M> ? M : never} M */
|
|
39
|
+
|
|
40
|
+
const moduleIdStr = module_.idToString(moduleId)
|
|
41
|
+
|
|
42
|
+
/** @type {(e: module_.Error) => (moduleMap: M) => Result<M>} */
|
|
43
|
+
const error = e => moduleMap => {
|
|
44
|
+
/** @type {module_.State} */
|
|
45
|
+
const state = ['error', e]
|
|
46
|
+
return [state, moduleMapInterface.insert(moduleIdStr)(state)(moduleMap)]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @type {function_.Require<readonly[M, map.Map<string>]>} */
|
|
50
|
+
const require_ = path => ([moduleMap, requireMap]) => {
|
|
51
|
+
return todo()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return moduleMapFirst => {
|
|
55
|
+
let moduleMap = moduleMapFirst
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
const m = moduleMapInterface.at(moduleIdStr)(moduleMap)
|
|
59
|
+
if (m !== undefined) { return [m, moduleMap] }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const p = packageGet(moduleId.packageId)
|
|
63
|
+
if (p === undefined) { return notFound(moduleMap) }
|
|
64
|
+
|
|
65
|
+
const source = p.file(moduleId.path.join('/'))
|
|
66
|
+
if (source === undefined) { return notFound(moduleMap) }
|
|
67
|
+
|
|
68
|
+
const compileResult = compile(source)
|
|
69
|
+
if (compileResult[0] === 'error') { return error(['compilation error', compileResult[1]])(moduleMap) }
|
|
70
|
+
|
|
71
|
+
const moduleFunction = compileResult[1]
|
|
72
|
+
|
|
73
|
+
moduleMap = moduleMapInterface.insert(moduleIdStr)(['building'])(moduleMap)
|
|
74
|
+
|
|
75
|
+
const [[type, exportsOrError], [newModuleMap, requireMap]] = moduleFunction(require_)([moduleMap, map.empty])
|
|
76
|
+
moduleMap = newModuleMap
|
|
77
|
+
|
|
78
|
+
{
|
|
79
|
+
const m = moduleMapInterface.at(moduleIdStr)(moduleMap)
|
|
80
|
+
if (m === undefined ) { throw 'm === undefined' }
|
|
81
|
+
if (m[0] !== 'building') { return [m, moduleMap] }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @type {module_.State} */
|
|
85
|
+
const result = type === 'error' ?
|
|
86
|
+
['error', ['runtime error', exportsOrError]] :
|
|
87
|
+
['ok', {
|
|
88
|
+
exports: exportsOrError,
|
|
89
|
+
requireMap: object.fromMap(requireMap)
|
|
90
|
+
}]
|
|
91
|
+
|
|
92
|
+
return [result, moduleMapInterface.insert(moduleIdStr)(result)(moduleMap)]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = {
|
|
97
|
+
/** @readonly */
|
|
98
|
+
getOrBuild,
|
|
99
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An IO interface for creating and running module functions.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const result = require('../../../types/result')
|
|
6
|
+
|
|
7
|
+
/** @typedef {<M>(require: Require<M>) => (prior: M) => Result<M>} Function_ */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @template M
|
|
11
|
+
* @typedef {readonly[result.Result<unknown, unknown>, M]} Result
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @template M
|
|
16
|
+
* @typedef {(path: string) => (prior: M) => Result<M>} Require
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** @typedef {(source: string) => result.Result<Function_, unknown>} Compile */
|
|
20
|
+
|
|
21
|
+
module.exports = {}
|
package/commonjs/module/index.js
CHANGED
|
@@ -3,17 +3,17 @@ const object = require('../../types/object')
|
|
|
3
3
|
/**
|
|
4
4
|
* @template M
|
|
5
5
|
* @typedef {{
|
|
6
|
-
* readonly at: (moduleId: string) => (moduleMap: M) =>
|
|
7
|
-
* readonly insert: (moduleId: string) => (moduleState:
|
|
8
|
-
* }}
|
|
6
|
+
* readonly at: (moduleId: string) => (moduleMap: M) => State | undefined
|
|
7
|
+
* readonly insert: (moduleId: string) => (moduleState: State) => (moduleMap: M) => M
|
|
8
|
+
* }} MapInterface
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
12
|
* @typedef {|
|
|
13
|
-
* readonly['ok', Module] |
|
|
14
|
-
* readonly['error',
|
|
13
|
+
* readonly['ok', Module] |
|
|
14
|
+
* readonly['error', Error] |
|
|
15
15
|
* readonly['building']
|
|
16
|
-
* }
|
|
16
|
+
* } State
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -23,13 +23,26 @@ const object = require('../../types/object')
|
|
|
23
23
|
* }} Module
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
27
|
* @typedef {|
|
|
28
|
-
* 'file not found' |
|
|
29
|
-
* '
|
|
30
|
-
* 'runtime error' |
|
|
31
|
-
* 'circular reference'
|
|
32
|
-
* }
|
|
28
|
+
* ['file not found'] |
|
|
29
|
+
* ['compilation error', unknown] |
|
|
30
|
+
* ['runtime error', unknown] |
|
|
31
|
+
* ['circular reference']
|
|
32
|
+
* } Error
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {{
|
|
37
|
+
* readonly packageId: string
|
|
38
|
+
* readonly path: readonly string[]
|
|
39
|
+
* }} Id
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/** @type {(id: Id) => string} */
|
|
43
|
+
const idToString = ({ packageId, path }) => `${packageId}/${path.join('/')}`
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
/** @readonly */
|
|
47
|
+
idToString,
|
|
48
|
+
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
const json = require('../../json')
|
|
2
|
-
const
|
|
3
|
-
const object = require('../../types/object')
|
|
4
|
-
const run = require('../run')
|
|
2
|
+
const dependencies = require('./dependencies')
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* @typedef {{
|
|
8
6
|
* readonly name: string
|
|
9
7
|
* readonly version: string
|
|
10
|
-
* readonly dependencies?:
|
|
8
|
+
* readonly dependencies?: dependencies.DependenciesJson
|
|
11
9
|
* }} PackageJson
|
|
12
10
|
*/
|
|
13
11
|
|
|
@@ -16,7 +14,7 @@ const isPackageJson = j => {
|
|
|
16
14
|
if (!json.isObject(j)) { return false }
|
|
17
15
|
if (typeof j.name !== 'string') { return false }
|
|
18
16
|
if (typeof j.version !== 'string') { return false }
|
|
19
|
-
if (!
|
|
17
|
+
if (!dependencies.isDependenciesJson(j.dependencies)) { return false }
|
|
20
18
|
return true
|
|
21
19
|
}
|
|
22
20
|
|
|
@@ -27,7 +25,7 @@ const isPackageJson = j => {
|
|
|
27
25
|
* }} Package
|
|
28
26
|
*/
|
|
29
27
|
|
|
30
|
-
/** @typedef {(packageId: string) => Package | undefined}
|
|
28
|
+
/** @typedef {(packageId: string) => Package | undefined} Get */
|
|
31
29
|
|
|
32
30
|
module.exports = {
|
|
33
31
|
/** @readonly */
|
package/commonjs/path/index.js
CHANGED
|
@@ -7,12 +7,12 @@ const { at } = require("../../types/object")
|
|
|
7
7
|
|
|
8
8
|
/** @typedef {readonly string[]} Items */
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
11
|
* @typedef {{
|
|
12
12
|
* readonly external: boolean
|
|
13
13
|
* readonly dir: boolean
|
|
14
14
|
* readonly items: Items
|
|
15
|
-
* }} LocalPath
|
|
15
|
+
* }} LocalPath
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/** @type {(path: string) => readonly string[]} */
|
|
@@ -74,9 +74,9 @@ const variants = prior => () => {
|
|
|
74
74
|
return { first: n, tail: variants(n) }
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
/** @type {(d:
|
|
77
|
+
/** @type {(d: (local: string) => string|undefined) => (p: IdPath) => IdPath|undefined} */
|
|
78
78
|
const mapDependency = d => ([external, internal]) => {
|
|
79
|
-
const id =
|
|
79
|
+
const id = d(external)
|
|
80
80
|
return id === undefined ? undefined : [id, internal]
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -88,16 +88,21 @@ const mapDependency = d => ([external, internal]) => {
|
|
|
88
88
|
* }} Path
|
|
89
89
|
*/
|
|
90
90
|
|
|
91
|
-
/** @type {(d:
|
|
91
|
+
/** @type {(d: (local: string) => string|undefined) => (dir: boolean) => (items: seq.List<string>) => Path|undefined} */
|
|
92
92
|
const parseGlobal = d => dir => items => {
|
|
93
|
-
if (d === undefined) { return undefined }
|
|
94
93
|
const v = variants([undefined, items])
|
|
95
94
|
const r = seq.first(undefined)(seq.filterMap(mapDependency(d))(v))
|
|
96
95
|
if (r === undefined) { return undefined }
|
|
97
96
|
return { name: r[0], items: seq.toArray(r[1]), dir }
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* @type {(name: string) =>
|
|
101
|
+
* (dependencies: (local: string) => string|undefined) =>
|
|
102
|
+
* (local: string) =>
|
|
103
|
+
* (path: string) =>
|
|
104
|
+
* Path|undefined }
|
|
105
|
+
*/
|
|
101
106
|
const parse = name => dependencies => local => path => {
|
|
102
107
|
const parsed = parseLocal(local)(path)
|
|
103
108
|
if (parsed === undefined) { return undefined }
|
package/commonjs/path/test.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const _ = require('.')
|
|
2
2
|
const json = require('../../json')
|
|
3
3
|
const { identity } = require('../../types/function')
|
|
4
|
+
const { at } = require('../../types/object')
|
|
4
5
|
|
|
5
6
|
/** @type {(g: json.Unknown|undefined) => string} */
|
|
6
7
|
const stringify = g => {
|
|
@@ -45,20 +46,20 @@ const stringify = g => {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
{
|
|
48
|
-
if (_.parseGlobal(undefined)(false)(['a', 'b']) !== undefined) { throw 'error' }
|
|
49
|
-
if (_.parseGlobal(
|
|
50
|
-
if (_.parseGlobal({ b: 'x' })(false)(['d']) !== undefined) { throw 'error' }
|
|
49
|
+
if (_.parseGlobal(() => undefined)(false)(['a', 'b']) !== undefined) { throw 'error' }
|
|
50
|
+
if (_.parseGlobal(() => undefined)(false)(['b']) !== undefined) { throw 'error' }
|
|
51
|
+
if (_.parseGlobal(d => at(d)({ b: 'x' }))(false)(['d']) !== undefined) { throw 'error' }
|
|
51
52
|
{
|
|
52
|
-
const result = stringify(_.parseGlobal({ b: 'x' })(false)(['b']))
|
|
53
|
+
const result = stringify(_.parseGlobal(d => at(d)({ b: 'x' }))(false)(['b']))
|
|
53
54
|
if (result !== '["x",""]') { throw result }
|
|
54
55
|
}
|
|
55
|
-
if (_.parseGlobal({ 'b/r': 'x' })(false)(['b']) !== undefined) { throw 'error' }
|
|
56
|
+
if (_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b']) !== undefined) { throw 'error' }
|
|
56
57
|
{
|
|
57
|
-
const result = stringify(_.parseGlobal({ 'b/r': 'x' })(false)(['b', 'r']))
|
|
58
|
+
const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b', 'r']))
|
|
58
59
|
if (result !== '["x",""]') { throw result }
|
|
59
60
|
}
|
|
60
61
|
{
|
|
61
|
-
const result = stringify(_.parseGlobal({ 'b/r': 'x' })(false)(['b', 'r', 'd', 't']))
|
|
62
|
+
const result = stringify(_.parseGlobal(d => at(d)({ 'b/r': 'x' }))(false)(['b', 'r', 'd', 't']))
|
|
62
63
|
if (result !== '["x","d/t"]') { throw result }
|
|
63
64
|
}
|
|
64
65
|
}
|
package/io/commonjs/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
const { tryCatch } = require('../result')
|
|
2
2
|
const { unwrap } = require('../../types/result')
|
|
3
|
-
const
|
|
3
|
+
const moduleFunction = require('../../commonjs/module/function')
|
|
4
4
|
|
|
5
|
-
/** @type {(f: Function) =>
|
|
5
|
+
/** @type {(f: Function) => moduleFunction.Function_} */
|
|
6
6
|
const build = f => immutableRequire => mutableData => {
|
|
7
7
|
/** @type {(path: string) => unknown} */
|
|
8
8
|
const mutableRequire = path => {
|
|
9
9
|
const [result, data] = immutableRequire(path)(mutableData)
|
|
10
|
+
// Side effect: setting a variable from a nested function (closure)
|
|
11
|
+
// is not allowed in FunctionalScript.
|
|
10
12
|
mutableData = data
|
|
11
13
|
return unwrap(result)
|
|
12
14
|
}
|
|
@@ -18,8 +20,9 @@ const build = f => immutableRequire => mutableData => {
|
|
|
18
20
|
return [result, mutableData]
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
/** @type {
|
|
22
|
-
const compile = source =>
|
|
23
|
+
/** @type {moduleFunction.Compile} */
|
|
24
|
+
const compile = source =>
|
|
25
|
+
// Side effect: a `Function` constructor is not allowed in FunctionalScript.
|
|
23
26
|
tryCatch(() => build(Function('module', 'require', `"use strict";${source}`)))
|
|
24
27
|
|
|
25
28
|
module.exports = {
|
package/io/commonjs/test.js
CHANGED
package/io/result/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const result = require('../../types/result')
|
|
|
2
2
|
|
|
3
3
|
/** @type {<T>(f: () => T) => result.Result<T, unknown>} */
|
|
4
4
|
const tryCatch = f => {
|
|
5
|
+
// Side effect: `try catch` is not allowed in FunctionalScript.
|
|
5
6
|
try {
|
|
6
7
|
return result.ok(f())
|
|
7
8
|
} catch (e) {
|
|
@@ -12,4 +13,4 @@ const tryCatch = f => {
|
|
|
12
13
|
module.exports = {
|
|
13
14
|
/** @readonly */
|
|
14
15
|
tryCatch,
|
|
15
|
-
}
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functionalscript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.268",
|
|
4
4
|
"description": "FunctionalScript is a functional subset of JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"functional-programming",
|
|
20
20
|
"closure",
|
|
21
21
|
"pure-functional",
|
|
22
|
-
"typescript"
|
|
22
|
+
"typescript",
|
|
23
|
+
"programming-language",
|
|
24
|
+
"lazy-evaluation"
|
|
23
25
|
],
|
|
24
26
|
"bugs": {
|
|
25
27
|
"url": "https://github.com/functionalscript/functionalscript/issues"
|
package/types/btree/index.js
CHANGED
|
@@ -36,8 +36,8 @@ const seq = require('../list')
|
|
|
36
36
|
//
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* @template T
|
|
40
|
-
* @typedef {Array1<T>} Leaf1
|
|
39
|
+
* @template T
|
|
40
|
+
* @typedef {Array1<T>} Leaf1
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
43
|
/**
|
|
@@ -62,9 +62,9 @@ const seq = require('../list')
|
|
|
62
62
|
|
|
63
63
|
/** @typedef {readonly['done']} NotFoundDone */
|
|
64
64
|
|
|
65
|
-
/**
|
|
65
|
+
/**
|
|
66
66
|
* @template T
|
|
67
|
-
* @typedef {readonly['done', T]} FoundDone
|
|
67
|
+
* @typedef {readonly['done', T]} FoundDone
|
|
68
68
|
*/
|
|
69
69
|
|
|
70
70
|
/**
|
|
@@ -92,7 +92,7 @@ const seq = require('../list')
|
|
|
92
92
|
/** @typedef {<T>(_: Lazy<T>) => (_: Branch3<T>) => Result<T>} InBranch3 */
|
|
93
93
|
/** @typedef {<T>(_: Lazy<T>) => (_: Branch5<T>) => Result<T>} InBranch5 */
|
|
94
94
|
|
|
95
|
-
/**
|
|
95
|
+
/**
|
|
96
96
|
* @typedef {{
|
|
97
97
|
* readonly leaf1: InLeaf1
|
|
98
98
|
* readonly leaf2_left: InLeaf2
|
|
@@ -113,7 +113,7 @@ const seq = require('../list')
|
|
|
113
113
|
* }} NotFound
|
|
114
114
|
*/
|
|
115
115
|
|
|
116
|
-
/**
|
|
116
|
+
/**
|
|
117
117
|
* @typedef {{
|
|
118
118
|
* readonly found: Found
|
|
119
119
|
* readonly notFound: NotFound
|
|
@@ -128,11 +128,11 @@ const seq = require('../list')
|
|
|
128
128
|
/** @type {<T>(n: Branch7<T>) => Branch3<T>} */
|
|
129
129
|
const split = ([n0, v1, n2, v3, n4, v5, n6]) => [[n0, v1, n2], v3, [n4, v5, n6]]
|
|
130
130
|
|
|
131
|
-
/**
|
|
132
|
-
* @type {<T>(extend: (o: Branch3<T>) => Result<T>) =>
|
|
133
|
-
* (replace: (r: Node<T>) => Node<T>) =>
|
|
134
|
-
* (result: Result<T>) =>
|
|
135
|
-
* Result<T>}
|
|
131
|
+
/**
|
|
132
|
+
* @type {<T>(extend: (o: Branch3<T>) => Result<T>) =>
|
|
133
|
+
* (replace: (r: Node<T>) => Node<T>) =>
|
|
134
|
+
* (result: Result<T>) =>
|
|
135
|
+
* Result<T>}
|
|
136
136
|
*/
|
|
137
137
|
const merge = extend => replace => result => {
|
|
138
138
|
switch (result[0]) {
|
|
@@ -147,17 +147,17 @@ const visit = ({ found, notFound }) => cmp => {
|
|
|
147
147
|
const i3 = index3(cmp)
|
|
148
148
|
const i5 = index5(cmp)
|
|
149
149
|
/** @typedef {typeof cmp extends Cmp<infer T> ? T : never} T */
|
|
150
|
-
/**
|
|
151
|
-
* @type {(extend: (o: Branch3<T>) => Branch5<T>) =>
|
|
152
|
-
* (replace: (r: Node<T>) => Branch3<T>) =>
|
|
153
|
-
* (result: Result<T>) =>
|
|
154
|
-
* Result<T>}
|
|
150
|
+
/**
|
|
151
|
+
* @type {(extend: (o: Branch3<T>) => Branch5<T>) =>
|
|
152
|
+
* (replace: (r: Node<T>) => Branch3<T>) =>
|
|
153
|
+
* (result: Result<T>) =>
|
|
154
|
+
* Result<T>}
|
|
155
155
|
*/
|
|
156
156
|
const merge2 = extend => merge(o => ['replace', extend(o)])
|
|
157
|
-
/**
|
|
158
|
-
* @type {(extend: (o: Branch3<T>) => Branch7<T>) =>
|
|
159
|
-
* (replace: (r: Node<T>) => Branch5<T>) =>
|
|
160
|
-
* (result: Result<T>) =>
|
|
157
|
+
/**
|
|
158
|
+
* @type {(extend: (o: Branch3<T>) => Branch7<T>) =>
|
|
159
|
+
* (replace: (r: Node<T>) => Branch5<T>) =>
|
|
160
|
+
* (result: Result<T>) =>
|
|
161
161
|
* Result<T>}
|
|
162
162
|
*/
|
|
163
163
|
const merge3 = extend => merge(o => ['overflow', split(extend(o))])
|
|
@@ -305,34 +305,31 @@ const replaceVisitor = {
|
|
|
305
305
|
|
|
306
306
|
/** @type {<T>(node: Node<T>) => seq.List<T>} */
|
|
307
307
|
const values = node => () => {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
])
|
|
326
|
-
}
|
|
308
|
+
switch (node.length) {
|
|
309
|
+
case 1: case 2: { return node }
|
|
310
|
+
case 3: {
|
|
311
|
+
return seq.flat([
|
|
312
|
+
values(node[0]),
|
|
313
|
+
[node[1]],
|
|
314
|
+
values(node[2])
|
|
315
|
+
])
|
|
316
|
+
}
|
|
317
|
+
default: {
|
|
318
|
+
return seq.flat([
|
|
319
|
+
values(node[0]),
|
|
320
|
+
[node[1]],
|
|
321
|
+
values(node[2]),
|
|
322
|
+
[node[3]],
|
|
323
|
+
values(node[4])
|
|
324
|
+
])
|
|
327
325
|
}
|
|
328
326
|
}
|
|
329
|
-
return seq.next(f())
|
|
330
327
|
}
|
|
331
328
|
|
|
332
329
|
module.exports = {
|
|
333
330
|
/** @readonly */
|
|
334
331
|
values,
|
|
335
|
-
/**
|
|
332
|
+
/**
|
|
336
333
|
* @readonly
|
|
337
334
|
* @type { <T>(cmp: Cmp<T>) => (node: Node<T>) => T|undefined }
|
|
338
335
|
*/
|
package/types/map/index.js
CHANGED
|
@@ -3,13 +3,13 @@ const btree = require('../btree')
|
|
|
3
3
|
const { getVisitor, setVisitor, values } = require("../btree")
|
|
4
4
|
const compare = require("../function/compare")
|
|
5
5
|
const { cmp } = require("../function/compare")
|
|
6
|
-
const
|
|
6
|
+
const list = require("../list")
|
|
7
7
|
|
|
8
8
|
/** @typedef {compare.Sign} Sign */
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* @template T
|
|
12
|
-
* @typedef {btree.Leaf1<T>} Leaf1
|
|
11
|
+
* @template T
|
|
12
|
+
* @typedef {btree.Leaf1<T>} Leaf1
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -27,7 +27,7 @@ const seq = require("../list")
|
|
|
27
27
|
* @typedef {readonly[string, T]} Entry
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
31
|
* @template T
|
|
32
32
|
* @typedef {undefined|TNode<Entry<T>>} Map
|
|
33
33
|
*/
|
|
@@ -54,16 +54,16 @@ const set = name => value => map => {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
/** @type {<T>(map: Map<T>) =>
|
|
58
|
-
const entries = map => map === undefined ?
|
|
57
|
+
/** @type {<T>(map: Map<T>) => list.List<Entry<T>>} */
|
|
58
|
+
const entries = map => map === undefined ? undefined : values(map)
|
|
59
59
|
|
|
60
60
|
/** @type {<T>(map: Map<T>) => (entry: Entry<T>) => Map<T>} */
|
|
61
61
|
const setOp = map => ([name, value]) => set(name)(value)(map)
|
|
62
62
|
|
|
63
|
-
/** @type {<T>(entries:
|
|
63
|
+
/** @type {<T>(entries: list.List<Entry<T>>) => Map<T>} */
|
|
64
64
|
const fromEntries = entries => {
|
|
65
|
-
/** @typedef {typeof entries extends
|
|
66
|
-
return
|
|
65
|
+
/** @typedef {typeof entries extends list.List<Entry<infer T>> ? T : never} T */
|
|
66
|
+
return list.reduce(setOp)(/** @type {Map<T>} */(undefined))(entries)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
module.exports = {
|
package/types/object/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const list = require('../list')
|
|
2
2
|
const map = require('../map')
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -16,12 +16,17 @@ const map = require('../map')
|
|
|
16
16
|
/** @type {(name: string) => <T>(object: Map<T>) => T|undefined} */
|
|
17
17
|
const at = name => object => Object.getOwnPropertyDescriptor(object, name)?.value
|
|
18
18
|
|
|
19
|
-
/** @type {<T>(entries:
|
|
19
|
+
/** @type {<T>(entries: list.List<Entry<T>>) => list.List<Entry<T>>} */
|
|
20
20
|
const sort = entries => map.entries(map.fromEntries(entries))
|
|
21
21
|
|
|
22
|
+
/** @type {<T>(m: map.Map<T>) => Map<T>} */
|
|
23
|
+
const fromMap = m => Object.fromEntries(list.iterable(map.entries(m)))
|
|
24
|
+
|
|
22
25
|
module.exports = {
|
|
23
26
|
/** @readonly */
|
|
24
27
|
at,
|
|
25
28
|
/** @readonly */
|
|
26
29
|
sort,
|
|
30
|
+
/** @readonly */
|
|
31
|
+
fromMap,
|
|
27
32
|
}
|
package/commonjs/run/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const result = require('../../types/result')
|
|
2
|
-
|
|
3
|
-
/** @typedef {<T>(req: Require<T>) => (prior: T) => ModuleResult<T>} Module*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @template T
|
|
7
|
-
* @typedef {readonly[result.Result<unknown, unknown>, T]} ModuleResult
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @template T
|
|
12
|
-
* @typedef {(path: string) => (prior: T) => ModuleResult<T>} Require
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/** @typedef {(source: string) => result.Result<Module, unknown>} Compile */
|
|
16
|
-
|
|
17
|
-
module.exports = {}
|