functionalscript 0.0.396 → 0.0.400
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 +2 -2
- package/types/bigint/module.f.cjs +3 -0
- package/types/btree/find/test.f.cjs +3 -3
- package/types/btree/remove/test.f.cjs +3 -3
- package/types/btree/set/module.f.cjs +14 -12
- package/types/btree/set/test.f.cjs +2 -2
- package/types/btree/test.f.cjs +4 -4
- package/types/function/compare/module.f.cjs +2 -10
- package/types/function/compare/test.f.cjs +3 -8
- package/types/map/module.f.cjs +16 -7
- package/types/map/test.f.cjs +12 -9
- package/types/number/module.f.cjs +7 -0
- package/types/number/test.f.cjs +6 -1
- package/types/string/module.f.cjs +7 -0
- package/types/string/test.f.cjs +6 -1
- package/types/string_set/module.f.cjs +4 -4
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functionalscript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.400",
|
|
4
4
|
"description": "FunctionalScript is a functional subset of JavaScript",
|
|
5
5
|
"main": "module.f.cjs",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/functionalscript/functionalscript#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^18.
|
|
32
|
+
"@types/node": "^18.7.8",
|
|
33
33
|
"typescript": "^4.7.4"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -3,19 +3,19 @@ const list = require('../../list/module.f.cjs')
|
|
|
3
3
|
const json = require('../../../json/module.f.cjs')
|
|
4
4
|
const { sort } = require('../../object/module.f.cjs')
|
|
5
5
|
const btree = require('../types/module.f.cjs')
|
|
6
|
-
const {
|
|
6
|
+
const { cmp } = require('../../string/module.f.cjs')
|
|
7
7
|
const s = require('../set/module.f.cjs')
|
|
8
8
|
|
|
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(
|
|
12
|
+
const set = node => value => s.set(cmp(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)))
|
|
16
16
|
|
|
17
17
|
/** @type {(i: string) => (m: btree.Node<string>) => string} */
|
|
18
|
-
const find = i => m => str(_.find(
|
|
18
|
+
const find = i => m => str(_.find(cmp(i))(m))
|
|
19
19
|
|
|
20
20
|
{
|
|
21
21
|
/** @type {btree.Node<string>} */
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const _ = require('./module.f.cjs')
|
|
2
2
|
const btree = require('../types/module.f.cjs')
|
|
3
3
|
const s = require('../set/module.f.cjs')
|
|
4
|
-
const {
|
|
4
|
+
const { cmp } = require('../../string/module.f.cjs')
|
|
5
5
|
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(
|
|
9
|
+
const set = node => value => s.set(cmp(value))(() => value)(node)
|
|
10
10
|
|
|
11
11
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string> | undefined} */
|
|
12
|
-
const remove = node => value => _.nodeRemove(
|
|
12
|
+
const remove = node => value => _.nodeRemove(cmp(value))(node)
|
|
13
13
|
|
|
14
14
|
const jsonStr = json.stringify(sort)
|
|
15
15
|
|
|
@@ -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 */
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const _ = require('./module.f.cjs')
|
|
2
2
|
const btree = require('../types/module.f.cjs')
|
|
3
|
-
const {
|
|
3
|
+
const { cmp } = require('../../string/module.f.cjs')
|
|
4
4
|
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(
|
|
8
|
+
const set = node => value => _.set(cmp(value))(() => value)(node)
|
|
9
9
|
|
|
10
10
|
const jsonStr = json.stringify(sort)
|
|
11
11
|
|
package/types/btree/test.f.cjs
CHANGED
|
@@ -2,7 +2,7 @@ const btree = require('./types/module.f.cjs')
|
|
|
2
2
|
const { values } = require('./module.f.cjs')
|
|
3
3
|
const json = require('../../json/module.f.cjs')
|
|
4
4
|
const { sort } = require('../object/module.f.cjs')
|
|
5
|
-
const {
|
|
5
|
+
const { cmp } = require('../string/module.f.cjs')
|
|
6
6
|
const list = require('../list/module.f.cjs')
|
|
7
7
|
const s = require('./set/module.f.cjs')
|
|
8
8
|
const f = require('./find/module.f.cjs')
|
|
@@ -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(
|
|
20
|
+
const set = node => value => s.set(cmp(value))(() => value)(node)
|
|
21
21
|
|
|
22
22
|
{
|
|
23
23
|
/** @type {btree.Node<string>} */
|
|
@@ -45,7 +45,7 @@ const set = node => value => s.set(stringCmp(value))(value)(node)
|
|
|
45
45
|
let _map = ['a']
|
|
46
46
|
_map = set(_map)('b')
|
|
47
47
|
_map = set(_map)('c')
|
|
48
|
-
const result = f.value(f.find(
|
|
48
|
+
const result = f.value(f.find(cmp('b'))(_map).first)
|
|
49
49
|
if (result !== 'b') { throw result }
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -54,7 +54,7 @@ const set = node => value => s.set(stringCmp(value))(value)(node)
|
|
|
54
54
|
let _map = ['a']
|
|
55
55
|
_map = set(_map)('b')
|
|
56
56
|
_map = set(_map)('c')
|
|
57
|
-
const result = f.value(f.find(
|
|
57
|
+
const result = f.value(f.find(cmp('e'))(_map).first)
|
|
58
58
|
if (result !== undefined) { throw result }
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -27,19 +27,11 @@ const index5 = cmp => ([v0, v1]) => {
|
|
|
27
27
|
/** @type {<T>(a: T) => (b: T) => Sign} */
|
|
28
28
|
const unsafeCmp = a => b => a < b ? -1 : a === b ? 0 : 1
|
|
29
29
|
|
|
30
|
-
/** @type {(a: string) => (b: string) => Sign} */
|
|
31
|
-
const stringCmp = unsafeCmp
|
|
32
|
-
|
|
33
|
-
/** @type {(a: number) => (b: number) => Sign} */
|
|
34
|
-
const numberCmp = unsafeCmp
|
|
35
|
-
|
|
36
30
|
module.exports = {
|
|
31
|
+
/** @readonly */
|
|
32
|
+
unsafeCmp,
|
|
37
33
|
/** @readonly */
|
|
38
34
|
index3,
|
|
39
35
|
/** @readonly */
|
|
40
36
|
index5,
|
|
41
|
-
/** @readonly */
|
|
42
|
-
stringCmp,
|
|
43
|
-
/** @readonly */
|
|
44
|
-
numberCmp,
|
|
45
37
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { unsafeCmp } = require('./module.f.cjs')
|
|
2
2
|
|
|
3
3
|
{
|
|
4
|
-
const result =
|
|
5
|
-
if (result !==
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
{
|
|
9
|
-
const result = _.stringCmp('3')('4')
|
|
10
|
-
if (result !== -1) { throw result }
|
|
4
|
+
const result = unsafeCmp(true)(false)
|
|
5
|
+
if (result !== 1) { throw result }
|
|
11
6
|
}
|
|
12
7
|
|
|
13
8
|
module.exports = {}
|
package/types/map/module.f.cjs
CHANGED
|
@@ -4,10 +4,11 @@ const btreeFind = require('../btree/find/module.f.cjs')
|
|
|
4
4
|
const { value, find } = btreeFind
|
|
5
5
|
const btreeSet = require('../btree/set/module.f.cjs').set
|
|
6
6
|
const compare = require('../function/compare/module.f.cjs')
|
|
7
|
-
const {
|
|
7
|
+
const { cmp } = require('../string/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
|
|
|
@@ -27,7 +28,7 @@ const { remove: btreeRemove } = require('../btree/remove/module.f.cjs')
|
|
|
27
28
|
*/
|
|
28
29
|
|
|
29
30
|
/** @type {(a: string) => <T>(b: Entry<T>) => Sign} */
|
|
30
|
-
const keyCmp = a => ([b]) =>
|
|
31
|
+
const keyCmp = a => ([b]) => cmp(a)(b)
|
|
31
32
|
|
|
32
33
|
/** @type {(name: string) => <T>(map: Map<T>) => T|undefined} */
|
|
33
34
|
const at = name => map => {
|
|
@@ -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}`)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const { fold } = require('../list/module.f.cjs')
|
|
2
2
|
const { addition, min: minOp, max: maxOp } = require('../function/operator/module.f.cjs')
|
|
3
|
+
const compare = require('../function/compare/module.f.cjs')
|
|
4
|
+
const { unsafeCmp } = compare
|
|
3
5
|
|
|
4
6
|
const sum = fold(addition)(0)
|
|
5
7
|
|
|
@@ -7,6 +9,9 @@ const min = fold(minOp)(undefined)
|
|
|
7
9
|
|
|
8
10
|
const max = fold(maxOp)(undefined)
|
|
9
11
|
|
|
12
|
+
/** @type {(a: number) => (b: number) => compare.Sign} */
|
|
13
|
+
const cmp = unsafeCmp
|
|
14
|
+
|
|
10
15
|
module.exports = {
|
|
11
16
|
/** @readonly */
|
|
12
17
|
sum,
|
|
@@ -14,4 +19,6 @@ module.exports = {
|
|
|
14
19
|
min,
|
|
15
20
|
/** @readonly */
|
|
16
21
|
max,
|
|
22
|
+
/** @readonly */
|
|
23
|
+
cmp,
|
|
17
24
|
}
|
package/types/number/test.f.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { sum, min, max } = require('./module.f.cjs')
|
|
1
|
+
const { sum, min, max, cmp } = require('./module.f.cjs')
|
|
2
2
|
|
|
3
3
|
{
|
|
4
4
|
const result = sum([2, 3, 4, 5])
|
|
@@ -20,4 +20,9 @@ const { sum, min, max } = require('./module.f.cjs')
|
|
|
20
20
|
if (result !== 12) { throw result }
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
{
|
|
24
|
+
const result = cmp(4)(5)
|
|
25
|
+
if (result !== -1) { throw result }
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
module.exports = {}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const list = require('../list/module.f.cjs')
|
|
2
2
|
const { fold: listFold, repeat: listRepeat } = list
|
|
3
3
|
const { compose } = require('../function/module.f.cjs')
|
|
4
|
+
const compare = require('../function/compare/module.f.cjs')
|
|
5
|
+
const { unsafeCmp } = compare
|
|
4
6
|
const op = require('../function/operator/module.f.cjs')
|
|
5
7
|
const { join: joinOp, concat: concatOp } = op
|
|
6
8
|
|
|
@@ -14,6 +16,9 @@ const concat = fold(concatOp)
|
|
|
14
16
|
/** @type {(n: string) => (v: number) => string} */
|
|
15
17
|
const repeat = v => compose(listRepeat(v))(concat)
|
|
16
18
|
|
|
19
|
+
/** @type {(a: string) => (b: string) => compare.Sign} */
|
|
20
|
+
const cmp = unsafeCmp
|
|
21
|
+
|
|
17
22
|
module.exports = {
|
|
18
23
|
/** @readonly */
|
|
19
24
|
join,
|
|
@@ -21,4 +26,6 @@ module.exports = {
|
|
|
21
26
|
concat,
|
|
22
27
|
/** @readonly */
|
|
23
28
|
repeat,
|
|
29
|
+
/** @readonly */
|
|
30
|
+
cmp,
|
|
24
31
|
}
|
package/types/string/test.f.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { join, concat, repeat } = require('./module.f.cjs')
|
|
1
|
+
const { join, concat, repeat, cmp } = require('./module.f.cjs')
|
|
2
2
|
const { repeat: repeatList } = require('../list/module.f.cjs')
|
|
3
3
|
|
|
4
4
|
{
|
|
@@ -36,4 +36,9 @@ const { repeat: repeatList } = require('../list/module.f.cjs')
|
|
|
36
36
|
if (s != 'xxxxx') { throw s }
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
{
|
|
40
|
+
const result = cmp('3')('4')
|
|
41
|
+
if (result !== -1) { throw result }
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
module.exports = {}
|
|
@@ -7,7 +7,7 @@ const {
|
|
|
7
7
|
/** @type {(s: StringSet) => list.List<string>} */
|
|
8
8
|
values,
|
|
9
9
|
} = btree
|
|
10
|
-
const {
|
|
10
|
+
const { cmp } = require("../string/module.f.cjs")
|
|
11
11
|
const list = require('../list/module.f.cjs')
|
|
12
12
|
const { reduce } = list
|
|
13
13
|
const { compose } = require('../function/module.f.cjs')
|
|
@@ -15,15 +15,15 @@ const { compose } = require('../function/module.f.cjs')
|
|
|
15
15
|
/** @typedef {btTypes.Tree<string>} StringSet */
|
|
16
16
|
|
|
17
17
|
/** @type {(value: string) => (set: StringSet) => boolean} */
|
|
18
|
-
const contains = value => s => s !== undefined && isFound(find(
|
|
18
|
+
const contains = value => s => s !== undefined && isFound(find(cmp(value))(s).first)
|
|
19
19
|
|
|
20
20
|
/** @type {(value: string) => (s: StringSet) => StringSet} */
|
|
21
|
-
const set = value => btreeSet(
|
|
21
|
+
const set = value => btreeSet(cmp(value))(() => value)
|
|
22
22
|
|
|
23
23
|
const fromValues = reduce(set)(undefined)
|
|
24
24
|
|
|
25
25
|
/** @type {(value: string) => (s: StringSet) => StringSet} */
|
|
26
|
-
const remove = compose(
|
|
26
|
+
const remove = compose(cmp)(btreeRemove)
|
|
27
27
|
|
|
28
28
|
module.exports = {
|
|
29
29
|
/** @readonly */
|