functionalscript 0.0.238 → 0.0.239
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/run/index.js +1 -1
- package/io/commonjs/index.js +1 -1
- package/io/commonjs/test.js +1 -1
- package/package.json +1 -1
- package/types/map/index.js +38 -44
- package/types/map/test.js +34 -33
- package/types/object/index.js +2 -1
package/commonjs/run/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const result = require('../../types/result')
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @template T
|
|
12
|
-
* @typedef {(
|
|
12
|
+
* @typedef {(path: string) => (prior: T) => ModuleResult<T>} Require
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
/** @typedef {(source: string) => result.Result<Module, unknown>} Compile */
|
package/io/commonjs/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const run = require('../../commonjs/run')
|
|
|
6
6
|
const build = f => immutableRequire => mutableData => {
|
|
7
7
|
/** @type {(path: string) => unknown} */
|
|
8
8
|
const mutableRequire = path => {
|
|
9
|
-
const [result, data] = immutableRequire(
|
|
9
|
+
const [result, data] = immutableRequire(path)(mutableData)
|
|
10
10
|
mutableData = data
|
|
11
11
|
return unwrap(result)
|
|
12
12
|
}
|
package/io/commonjs/test.js
CHANGED
package/package.json
CHANGED
package/types/map/index.js
CHANGED
|
@@ -1,86 +1,80 @@
|
|
|
1
1
|
const option = require("../option")
|
|
2
|
+
const btree = require('../btree')
|
|
2
3
|
const { getVisitor, setVisitor, values } = require("../btree")
|
|
4
|
+
const compare = require("../function/compare")
|
|
3
5
|
const { cmp } = require("../function/compare")
|
|
4
6
|
const seq = require("../sequence")
|
|
5
7
|
|
|
6
|
-
/** @typedef {
|
|
8
|
+
/** @typedef {compare.Sign} Sign */
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* @template T
|
|
10
|
-
* @typedef {
|
|
12
|
+
* @typedef {btree.Leaf1<T>} Leaf1
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* @template T
|
|
15
|
-
* @typedef {
|
|
17
|
+
* @typedef {btree.Node<T>} TNode
|
|
16
18
|
*/
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* @template T
|
|
20
|
-
* @typedef {
|
|
22
|
+
* @typedef {compare.Compare<T>} Cmp
|
|
21
23
|
*/
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* @template T
|
|
25
|
-
* @typedef {readonly
|
|
27
|
+
* @typedef {readonly[string, T]} Entry
|
|
26
28
|
*/
|
|
27
29
|
|
|
28
|
-
/**
|
|
30
|
+
/**
|
|
29
31
|
* @template T
|
|
30
|
-
* @typedef {
|
|
31
|
-
* readonly get: (name: string) => T|undefined
|
|
32
|
-
* readonly set: (name: string) => (value: T) => Map<T>
|
|
33
|
-
* readonly entries: seq.Sequence<Entry<T>>
|
|
34
|
-
* readonly root: undefined|TNode<Entry<T>>
|
|
35
|
-
* }} Map
|
|
32
|
+
* @typedef {undefined|TNode<Entry<T>>} Map
|
|
36
33
|
*/
|
|
37
34
|
|
|
38
35
|
/** @type {(a: string) => <T>(b: Entry<T>) => Sign} */
|
|
39
36
|
const keyCmp = a => ([b]) => cmp(a)(b)
|
|
40
37
|
|
|
41
|
-
/** @type {<T>(
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
case 'replace': case 'overflow': { return create(result[1]) }
|
|
48
|
-
default: { throw '' }
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
entries: values(root),
|
|
52
|
-
root,
|
|
53
|
-
})
|
|
38
|
+
/** @type {(name: string) => <T>(map: Map<T>) => T|undefined} */
|
|
39
|
+
const at = name => map => {
|
|
40
|
+
if (map === undefined) { return undefined }
|
|
41
|
+
const result = getVisitor(keyCmp(name))(map)
|
|
42
|
+
return result === undefined ? undefined : result[1]
|
|
43
|
+
}
|
|
54
44
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
set: name => value => create([[name, value]]),
|
|
66
|
-
entries: [],
|
|
67
|
-
root: undefined
|
|
45
|
+
/** @type {(name: string) => <T>(value: T) => (map: Map<T>) => Map<T>} */
|
|
46
|
+
const insert = name => value => map => {
|
|
47
|
+
/** @type {Entry<typeof value>} */
|
|
48
|
+
const entry = [name, value]
|
|
49
|
+
if (map === undefined) { return [entry] }
|
|
50
|
+
const result = setVisitor(keyCmp(name))(() => entry)(map)
|
|
51
|
+
switch (result[0]) {
|
|
52
|
+
case 'replace': case 'overflow': { return result[1] }
|
|
53
|
+
default: { throw 'invalid BTree operation' }
|
|
54
|
+
}
|
|
68
55
|
}
|
|
69
56
|
|
|
57
|
+
/** @type {<T>(map: Map<T>) => seq.Sequence<Entry<T>>} */
|
|
58
|
+
const entries = map => map === undefined ? [] : values(map)
|
|
59
|
+
|
|
70
60
|
/** @type {<T>(map: Map<T>) => (entry: Entry<T>) => Map<T>} */
|
|
71
|
-
const
|
|
61
|
+
const insertOp = map => ([name, value]) => insert(name)(value)(map)
|
|
72
62
|
|
|
73
63
|
/** @type {<T>(entries: seq.Sequence<Entry<T>>) => Map<T>} */
|
|
74
64
|
const fromEntries = entries => {
|
|
75
|
-
/** @typedef {typeof entries extends seq.Sequence<Entry<infer T>> ? T : never} T */
|
|
76
|
-
/** @type {Map<T>} */
|
|
77
|
-
const init = empty
|
|
78
|
-
return seq.reduce(setOperator)(init)(entries)
|
|
65
|
+
/** @typedef {typeof entries extends seq.Sequence<Entry<infer T>> ? T : never} T */
|
|
66
|
+
return seq.reduce(insertOp)(/** @type {Map<T>} */(undefined))(entries)
|
|
79
67
|
}
|
|
80
68
|
|
|
81
69
|
module.exports = {
|
|
82
70
|
/** @readonly */
|
|
83
|
-
empty,
|
|
71
|
+
empty: undefined,
|
|
72
|
+
/** @readonly */
|
|
73
|
+
at,
|
|
74
|
+
/** @readonly */
|
|
75
|
+
insert,
|
|
76
|
+
/** @readonlg */
|
|
77
|
+
entries,
|
|
84
78
|
/** @readonly */
|
|
85
79
|
fromEntries,
|
|
86
80
|
}
|
package/types/map/test.js
CHANGED
|
@@ -1,59 +1,60 @@
|
|
|
1
|
-
const { empty } = require('.')
|
|
1
|
+
const { at, insert, empty, entries } = require('.')
|
|
2
2
|
const list = require('../sequence')
|
|
3
3
|
|
|
4
4
|
{
|
|
5
|
-
let m =
|
|
5
|
+
let m = insert('a')(1)(undefined)
|
|
6
6
|
|
|
7
|
-
if (
|
|
8
|
-
if (
|
|
7
|
+
if (at('a')(m) !== 1) { throw 'error' }
|
|
8
|
+
if (at('b')(m) !== undefined) { throw 'error' }
|
|
9
9
|
|
|
10
|
-
m =
|
|
10
|
+
m = insert('b')(2)(m)
|
|
11
11
|
|
|
12
|
-
if (
|
|
13
|
-
if (
|
|
14
|
-
if (
|
|
12
|
+
if (at('a')(m) !== 1) { throw 'error' }
|
|
13
|
+
if (at('b')(m) !== 2) { throw 'error' }
|
|
14
|
+
if (at('c')(m) !== undefined) { throw 'error' }
|
|
15
15
|
|
|
16
|
-
m =
|
|
16
|
+
m = insert('z')(3)(m)
|
|
17
17
|
|
|
18
|
-
if (
|
|
19
|
-
if (
|
|
20
|
-
if (
|
|
21
|
-
if (
|
|
18
|
+
if (at('a')(m) !== 1) { throw 'error' }
|
|
19
|
+
if (at('b')(m) !== 2) { throw 'error' }
|
|
20
|
+
if (at('z')(m) !== 3) { throw 'error' }
|
|
21
|
+
if (at('')(m) !== undefined) { throw 'error' }
|
|
22
22
|
|
|
23
|
-
m =
|
|
23
|
+
m = insert('')(4)(m)
|
|
24
24
|
|
|
25
|
-
if (
|
|
26
|
-
if (
|
|
27
|
-
if (
|
|
28
|
-
if (
|
|
29
|
-
if (
|
|
25
|
+
if (at('a')(m) !== 1) { throw 'error' }
|
|
26
|
+
if (at('b')(m) !== 2) { throw 'error' }
|
|
27
|
+
if (at('z')(m) !== 3) { throw 'error' }
|
|
28
|
+
if (at('')(m) !== 4) { throw 'error' }
|
|
29
|
+
if (at('Hello world!')(m) !== undefined) { throw 'error' }
|
|
30
30
|
|
|
31
|
-
m =
|
|
31
|
+
m = insert('Hello world!')(42)(m)
|
|
32
32
|
|
|
33
|
-
if (
|
|
34
|
-
if (
|
|
35
|
-
if (
|
|
36
|
-
if (
|
|
37
|
-
if (
|
|
38
|
-
if (
|
|
33
|
+
if (at('a')(m) !== 1) { throw 'error' }
|
|
34
|
+
if (at('b')(m) !== 2) { throw 'error' }
|
|
35
|
+
if (at('z')(m) !== 3) { throw 'error' }
|
|
36
|
+
if (at('')(m) !== 4) { throw 'error' }
|
|
37
|
+
if (at('Hello world!')(m) !== 42) { throw 'error' }
|
|
38
|
+
if (at('x')(m) !== undefined) { throw 'error' }
|
|
39
39
|
|
|
40
40
|
// console.log(Array.from(m.entries()))
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
let m = insert('x')(12)(undefined)
|
|
45
|
+
m = insert('y')(44)(m)
|
|
46
|
+
if (at('x')(m) !== 12) { throw 'error' }
|
|
47
|
+
if (at('y')(m) !== 44) { throw 'error' }
|
|
48
|
+
if (at('a')(m) !== undefined) { throw 'error' }
|
|
49
|
+
const e = list.toArray(entries(m))
|
|
50
|
+
if (e.length !== 2) { throw 'error' }
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
{
|
|
53
54
|
/** @type {import('.').Map<number>} */
|
|
54
55
|
let m = empty
|
|
55
56
|
for (let i = 0; i < 100_000; ++i) {
|
|
56
|
-
m =
|
|
57
|
+
m = insert((i * i).toString())(i)(m)
|
|
57
58
|
/*
|
|
58
59
|
console.log()
|
|
59
60
|
console.log(`# ${i}`)
|
package/types/object/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const seq = require('../sequence')
|
|
2
2
|
const map = require('../map')
|
|
3
|
+
const { compose } = require('../function')
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @template T
|
|
@@ -17,7 +18,7 @@ const map = require('../map')
|
|
|
17
18
|
const at = name => object => Object.getOwnPropertyDescriptor(object, name)?.value
|
|
18
19
|
|
|
19
20
|
/** @type {<T>(entries: seq.Sequence<Entry<T>>) => seq.Sequence<Entry<T>>} */
|
|
20
|
-
const sort = entries => map.fromEntries(entries)
|
|
21
|
+
const sort = entries => map.entries(map.fromEntries(entries))
|
|
21
22
|
|
|
22
23
|
module.exports = {
|
|
23
24
|
/** @readonly */
|