functionalscript 0.0.468 → 0.0.469
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
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const sortedList = require("../sorted_list/module.f.cjs")
|
|
2
2
|
const { genericMerge } = sortedList
|
|
3
3
|
const list = require("../list/module.f.cjs")
|
|
4
|
+
const { next } = list
|
|
4
5
|
const option = require("../option/module.f.cjs")
|
|
5
6
|
const { cmp } = require('../number/module.f.cjs')
|
|
6
7
|
const operator = require("../function/operator/module.f.cjs")
|
|
@@ -50,7 +51,7 @@ const reduceOp = union => equal => state => ([aItem, aMax]) => ([bItem, bMax])
|
|
|
50
51
|
/** @type {<T>(equal: operator.Equal<T>) => sortedList.TailReduce<Entry<T>, RangeState<T>>} */
|
|
51
52
|
const tailReduce = equal => state => tail => {
|
|
52
53
|
if (state === undefined) { return tail }
|
|
53
|
-
const tailResult =
|
|
54
|
+
const tailResult = next(tail)
|
|
54
55
|
if (tailResult === undefined) { return [state] }
|
|
55
56
|
if (equal(state[0])(tailResult.first[0])) { return tailResult }
|
|
56
57
|
return { first: state, tail: tailResult }
|
|
@@ -3,12 +3,18 @@ const list = require('../list/module.f.cjs')
|
|
|
3
3
|
const option = require('../option/module.f.cjs')
|
|
4
4
|
const { next } = list
|
|
5
5
|
const { identity } = require('../function/module.f.cjs')
|
|
6
|
+
const range = require('../range/module.f.cjs')
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @template T
|
|
9
10
|
* @typedef {list.List<T>} SortedList
|
|
10
11
|
*/
|
|
11
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @template T
|
|
15
|
+
* @typedef {readonly T[]} SortedArray
|
|
16
|
+
*/
|
|
17
|
+
|
|
12
18
|
/**
|
|
13
19
|
* @template T
|
|
14
20
|
* @typedef {(a: T) => (b: T) => compare.Sign} Cmp
|
|
@@ -78,9 +84,33 @@ const cmpReduce = cmp => () => a => b => {
|
|
|
78
84
|
/** @type {() => <T>(tail: list.List<T>) => list.List<T>} */
|
|
79
85
|
const mergeTail = () => identity
|
|
80
86
|
|
|
87
|
+
/** @type {<T>(cmp: Cmp<T>) => (value: T) => (array: SortedArray<T>) => T|undefined} */
|
|
88
|
+
const find = cmp => value => array => {
|
|
89
|
+
let b = 0
|
|
90
|
+
let e = array.length - 1
|
|
91
|
+
while (true) {
|
|
92
|
+
if (e - b < 0) return undefined
|
|
93
|
+
const mid = b + (e - b >> 1)
|
|
94
|
+
const sign = cmp(value)(array[mid])
|
|
95
|
+
switch(sign) {
|
|
96
|
+
case -1: {
|
|
97
|
+
e = mid - 1
|
|
98
|
+
break
|
|
99
|
+
}
|
|
100
|
+
case 0: { return value }
|
|
101
|
+
case 1: {
|
|
102
|
+
b = mid + 1
|
|
103
|
+
break
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
81
109
|
module.exports = {
|
|
82
110
|
/** @readonly */
|
|
83
111
|
merge,
|
|
84
112
|
/** @readonly */
|
|
85
|
-
genericMerge
|
|
113
|
+
genericMerge,
|
|
114
|
+
/** @readonly */
|
|
115
|
+
find
|
|
86
116
|
}
|
|
@@ -29,5 +29,23 @@ module.exports = {
|
|
|
29
29
|
const len = length(result)
|
|
30
30
|
if (len != n) { throw result }
|
|
31
31
|
}
|
|
32
|
+
],
|
|
33
|
+
find: [
|
|
34
|
+
() => {
|
|
35
|
+
const result = _.find(unsafeCmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
|
|
36
|
+
if (result !== 0) { throw result }
|
|
37
|
+
},
|
|
38
|
+
() => {
|
|
39
|
+
const result = _.find(unsafeCmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
|
|
40
|
+
if (result !== undefined) { throw result }
|
|
41
|
+
},
|
|
42
|
+
() => {
|
|
43
|
+
const result = _.find(unsafeCmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
|
|
44
|
+
if (result !== undefined) { throw result }
|
|
45
|
+
},
|
|
46
|
+
() => {
|
|
47
|
+
const result = _.find(unsafeCmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
|
|
48
|
+
if (result !== 80) { throw result }
|
|
49
|
+
}
|
|
32
50
|
]
|
|
33
51
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const compare = require("../function/compare/module.f.cjs")
|
|
2
2
|
const { toArray } = require("../list/module.f.cjs")
|
|
3
3
|
const sortedList = require("../sorted_list/module.f.cjs")
|
|
4
|
-
const { merge, genericMerge } = sortedList
|
|
5
|
-
const list = require("../list/module.f.cjs")
|
|
6
|
-
const option = require("../option/module.f.cjs")
|
|
4
|
+
const { merge, genericMerge, find } = sortedList
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* @template T
|
|
@@ -34,9 +32,14 @@ const intersectReduce = cmp => state => a => b => {
|
|
|
34
32
|
|
|
35
33
|
const intersectTail = () => () => undefined
|
|
36
34
|
|
|
35
|
+
/** @type {<T>(cmp: Cmp<T>) => (value: T) => (set: SortedSet<T>) => boolean} */
|
|
36
|
+
const has = cmp => value => set => find(cmp)(value)(set) === value
|
|
37
|
+
|
|
37
38
|
module.exports = {
|
|
38
39
|
/** @readonly */
|
|
39
40
|
union,
|
|
40
41
|
/** @readonly */
|
|
41
|
-
intersect
|
|
42
|
+
intersect,
|
|
43
|
+
/** @readonly */
|
|
44
|
+
has
|
|
42
45
|
}
|
|
@@ -40,5 +40,23 @@ module.exports = {
|
|
|
40
40
|
const result = stringify(toArray(_.intersect(unsafeCmp)([1, 2, 3])([])))
|
|
41
41
|
if (result !== '[]') { throw result }
|
|
42
42
|
}
|
|
43
|
+
],
|
|
44
|
+
has: [
|
|
45
|
+
() => {
|
|
46
|
+
const result = _.has(unsafeCmp)(0)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
|
|
47
|
+
if (!result) { throw result }
|
|
48
|
+
},
|
|
49
|
+
() => {
|
|
50
|
+
const result = _.has(unsafeCmp)(3)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
|
|
51
|
+
if (result) { throw result }
|
|
52
|
+
},
|
|
53
|
+
() => {
|
|
54
|
+
const result = _.has(unsafeCmp)(77)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
|
|
55
|
+
if (result) { throw result }
|
|
56
|
+
},
|
|
57
|
+
() => {
|
|
58
|
+
const result = _.has(unsafeCmp)(80)([0, 10, 20, 30, 40, 50, 60, 70, 80, 90])
|
|
59
|
+
if (!result) { throw result }
|
|
60
|
+
}
|
|
43
61
|
]
|
|
44
62
|
}
|