functionalscript 0.0.280 → 0.0.281
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/package.json +1 -1
- package/test.js +1 -0
- package/types/btree/test.js +4 -4
- package/types/function/compare/index.js +11 -3
- package/types/function/compare/test.js +13 -0
- package/types/map/index.js +2 -2
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -9,6 +9,7 @@ require('./io/commonjs/test')
|
|
|
9
9
|
require('./commonjs/package/dependencies/test')
|
|
10
10
|
require('./commonjs/package/test')
|
|
11
11
|
require('./commonjs/path/test')
|
|
12
|
+
require('./types/function/compare/test')
|
|
12
13
|
|
|
13
14
|
/** @type {() => never} */
|
|
14
15
|
const assert = () => { throw 'assert' }
|
package/types/btree/test.js
CHANGED
|
@@ -2,7 +2,7 @@ const btree = require('.')
|
|
|
2
2
|
const { getVisitor, setVisitor, values } = btree
|
|
3
3
|
const json = require('../../json')
|
|
4
4
|
const { sort } = require('../object')
|
|
5
|
-
const {
|
|
5
|
+
const { stringCmp } = require('../function/compare')
|
|
6
6
|
const list = require('../list')
|
|
7
7
|
|
|
8
8
|
/** @type {(sequence: list.List<json.Unknown>) => string} */
|
|
@@ -10,7 +10,7 @@ const stringify = sequence => json.stringify(sort)(list.toArray(sequence))
|
|
|
10
10
|
|
|
11
11
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
12
12
|
const set = node => value => {
|
|
13
|
-
const result = setVisitor(
|
|
13
|
+
const result = setVisitor(stringCmp(value))(node)(() => value)
|
|
14
14
|
switch (result[0]) {
|
|
15
15
|
case 'replace': case 'overflow': { return result[1] }
|
|
16
16
|
default: { return node }
|
|
@@ -43,7 +43,7 @@ const set = node => value => {
|
|
|
43
43
|
let _map = ['a']
|
|
44
44
|
_map = set(_map)('b')
|
|
45
45
|
_map = set(_map)('c')
|
|
46
|
-
const result = getVisitor(
|
|
46
|
+
const result = getVisitor(stringCmp('b'))(_map)
|
|
47
47
|
if (result === undefined) { throw result }
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -52,7 +52,7 @@ const set = node => value => {
|
|
|
52
52
|
let _map = ['a']
|
|
53
53
|
_map = set(_map)('b')
|
|
54
54
|
_map = set(_map)('c')
|
|
55
|
-
const result = getVisitor(
|
|
55
|
+
const result = getVisitor(stringCmp('e'))(_map)
|
|
56
56
|
if (result !== undefined) { throw result }
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @template T
|
|
6
|
-
* @typedef {import('../../array').Array2<T>} Array2
|
|
6
|
+
* @typedef {import('../../array').Array2<T>} Array2
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
/** @typedef {-1|0|1} Sign */
|
|
@@ -22,8 +22,14 @@ const index5 = cmp => ([v0, v1]) => {
|
|
|
22
22
|
return /** @type {Index5} */ (_0 <= 0 ? _0 + 1 : cmp(v1) + 3)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/** @type {<T>(a: T) => (b: T) => Sign} */
|
|
26
|
+
const unsafeCmp = a => b => a < b ? -1 : a === b ? 0 : 1
|
|
27
|
+
|
|
25
28
|
/** @type {(a: string) => (b: string) => Sign} */
|
|
26
|
-
const
|
|
29
|
+
const stringCmp = unsafeCmp
|
|
30
|
+
|
|
31
|
+
/** @type {(a: number) => (b: number) => Sign} */
|
|
32
|
+
const numberCmp = unsafeCmp
|
|
27
33
|
|
|
28
34
|
module.exports = {
|
|
29
35
|
/** @readonly */
|
|
@@ -31,5 +37,7 @@ module.exports = {
|
|
|
31
37
|
/** @readonly */
|
|
32
38
|
index5,
|
|
33
39
|
/** @readonly */
|
|
34
|
-
|
|
40
|
+
stringCmp,
|
|
41
|
+
/** @readonly */
|
|
42
|
+
numberCmp,
|
|
35
43
|
}
|
package/types/map/index.js
CHANGED
|
@@ -2,7 +2,7 @@ const option = require("../option")
|
|
|
2
2
|
const btree = require('../btree')
|
|
3
3
|
const { getVisitor, setVisitor, values } = require("../btree")
|
|
4
4
|
const compare = require("../function/compare")
|
|
5
|
-
const {
|
|
5
|
+
const { stringCmp } = require("../function/compare")
|
|
6
6
|
const list = require("../list")
|
|
7
7
|
|
|
8
8
|
/** @typedef {compare.Sign} Sign */
|
|
@@ -33,7 +33,7 @@ const list = require("../list")
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
/** @type {(a: string) => <T>(b: Entry<T>) => Sign} */
|
|
36
|
-
const keyCmp = a => ([b]) =>
|
|
36
|
+
const keyCmp = a => ([b]) => stringCmp(a)(b)
|
|
37
37
|
|
|
38
38
|
/** @type {(name: string) => <T>(map: Map<T>) => T|undefined} */
|
|
39
39
|
const at = name => map => {
|