functionalscript 0.0.437 → 0.0.439
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 +2 -2
- package/types/byte_set/module.f.cjs +8 -1
- package/types/byte_set/test.f.cjs +16 -1
- package/types/list/module.f.cjs +11 -9
- package/types/nibble_set/module.f.cjs +24 -12
- package/types/nibble_set/test.f.cjs +16 -1
- package/types/sorted_list/module.f.cjs +48 -28
- package/types/sorted_set/module.f.cjs +3 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functionalscript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.439",
|
|
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.8.
|
|
32
|
+
"@types/node": "^18.8.4",
|
|
33
33
|
"typescript": "^4.8.4"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -10,6 +10,9 @@ const has = n => s => ((s >> BigInt(n)) & 1n) === 1n
|
|
|
10
10
|
|
|
11
11
|
const empty = 0n
|
|
12
12
|
|
|
13
|
+
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
|
14
|
+
const universe = 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFFn
|
|
15
|
+
|
|
13
16
|
/** @type {(n: Byte) => ByteSet} */
|
|
14
17
|
const one = n => 1n << BigInt(n)
|
|
15
18
|
|
|
@@ -28,7 +31,7 @@ const intersect = a => b => a & b
|
|
|
28
31
|
const difference = a => b => intersect(a)(complement(b))
|
|
29
32
|
|
|
30
33
|
/** @type {(n: ByteSet) => ByteSet} */
|
|
31
|
-
const complement = n =>
|
|
34
|
+
const complement = n => universe ^ n
|
|
32
35
|
|
|
33
36
|
// additional operations
|
|
34
37
|
|
|
@@ -43,6 +46,8 @@ module.exports = {
|
|
|
43
46
|
/** @readonly */
|
|
44
47
|
empty,
|
|
45
48
|
/** @readonly */
|
|
49
|
+
universe,
|
|
50
|
+
/** @readonly */
|
|
46
51
|
has,
|
|
47
52
|
/** @readonly */
|
|
48
53
|
set,
|
|
@@ -54,4 +59,6 @@ module.exports = {
|
|
|
54
59
|
setRange,
|
|
55
60
|
/** @readonly */
|
|
56
61
|
range,
|
|
62
|
+
/** @readonly */
|
|
63
|
+
complement,
|
|
57
64
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const _ = require('./module.f.cjs')
|
|
2
|
+
const { every, countdown, map } = require('../list/module.f.cjs')
|
|
2
3
|
|
|
3
4
|
module.exports = {
|
|
4
5
|
has: [
|
|
@@ -37,5 +38,19 @@ module.exports = {
|
|
|
37
38
|
const result = _.unset(255)(a)
|
|
38
39
|
if (result !== 0n) { throw result }
|
|
39
40
|
}
|
|
40
|
-
]
|
|
41
|
+
],
|
|
42
|
+
universe: () => {
|
|
43
|
+
const x = every(map(v => _.has(v)(_.universe))(countdown(256)))
|
|
44
|
+
if (!x) { throw x }
|
|
45
|
+
},
|
|
46
|
+
compliment: {
|
|
47
|
+
empty: () => {
|
|
48
|
+
const r = _.complement(_.empty)
|
|
49
|
+
if (r !== _.universe) { throw r }
|
|
50
|
+
},
|
|
51
|
+
universe: () => {
|
|
52
|
+
const r = _.complement(_.universe)
|
|
53
|
+
if (r !== _.empty) { throw r }
|
|
54
|
+
},
|
|
55
|
+
}
|
|
41
56
|
}
|
package/types/list/module.f.cjs
CHANGED
|
@@ -294,16 +294,18 @@ const zip = a => b => () => {
|
|
|
294
294
|
return { first: [aResult.first, bResult.first], tail: zip(aResult.tail)(bResult.tail) }
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
-
/** @type {<T>(e: operator.Equal<T>) => (a: List<T>) => (b: List<T>) => List<boolean>} */
|
|
298
|
-
const equalZip = e => a => b => () => {
|
|
299
|
-
const [aResult, bResult] = [next(a), next(b)]
|
|
300
|
-
return aResult === undefined || bResult === undefined
|
|
301
|
-
? { first: aResult === bResult, tail: undefined }
|
|
302
|
-
: { first: e(aResult.first)(bResult.first), tail: equalZip(e)(aResult.tail)(bResult.tail) }
|
|
303
|
-
}
|
|
304
|
-
|
|
305
297
|
/** @type {<T>(e: operator.Equal<T>) => (a: List<T>) => (b: List<T>) => boolean} */
|
|
306
|
-
const equal = e =>
|
|
298
|
+
const equal = e => {
|
|
299
|
+
/** @typedef {typeof e extends operator.Equal<infer T> ? T : never} T */
|
|
300
|
+
/** @type {(a: List<T>) => (b: List<T>) => List<boolean>} */
|
|
301
|
+
const f = a => b => () => {
|
|
302
|
+
const [aResult, bResult] = [next(a), next(b)]
|
|
303
|
+
return aResult === undefined || bResult === undefined
|
|
304
|
+
? { first: aResult === bResult, tail: undefined }
|
|
305
|
+
: { first: e(aResult.first)(bResult.first), tail: f(aResult.tail)(bResult.tail) }
|
|
306
|
+
}
|
|
307
|
+
return a => b => every(f(a)(b))
|
|
308
|
+
}
|
|
307
309
|
|
|
308
310
|
module.exports = {
|
|
309
311
|
/** @readonly */
|
|
@@ -1,32 +1,44 @@
|
|
|
1
|
-
/** @typedef {number}
|
|
2
|
-
/** @typedef {number}
|
|
1
|
+
/** @typedef {number} NibbleSet */
|
|
2
|
+
/** @typedef {number} Nibble */
|
|
3
3
|
|
|
4
4
|
const empty = 0
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const universe = 0xFFFF
|
|
7
|
+
|
|
8
|
+
/** @type {(n: Nibble) => NibbleSet} */
|
|
9
|
+
const one = n => 1 << n
|
|
10
|
+
|
|
11
|
+
/** @type {(n: Nibble) => (s: NibbleSet) => boolean} */
|
|
7
12
|
const has = n => s => ((s >> n) & 1) === 1
|
|
8
13
|
|
|
9
|
-
/** @type {(n:
|
|
10
|
-
const set = n => s => s | (
|
|
14
|
+
/** @type {(n: Nibble) => (s: NibbleSet) => NibbleSet} */
|
|
15
|
+
const set = n => s => s | one(n)
|
|
16
|
+
|
|
17
|
+
/** @type {(n: NibbleSet) => NibbleSet} */
|
|
18
|
+
const complement = s => universe ^ s
|
|
11
19
|
|
|
12
|
-
/** @type {(n:
|
|
13
|
-
const unset = n => s => s &
|
|
20
|
+
/** @type {(n: Nibble) => (s: NibbleSet) => NibbleSet} */
|
|
21
|
+
const unset = n => s => s & complement(one(n))
|
|
14
22
|
|
|
15
|
-
/** @type {(r: readonly[number, number]) =>
|
|
16
|
-
|
|
23
|
+
/** @type {(r: readonly[number, number]) => NibbleSet} */
|
|
24
|
+
const range = ([a, b]) => one(b - a + 1) - 1 << a
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
/** @type {(r: readonly[number, number]) => (s: NibbleSet) => NibbleSet} */
|
|
27
|
+
const setRange = r => s => s | range(r)
|
|
20
28
|
|
|
21
29
|
module.exports = {
|
|
22
30
|
/** @readonly */
|
|
23
31
|
empty,
|
|
24
32
|
/** @readonly */
|
|
33
|
+
universe,
|
|
34
|
+
/** @readonly */
|
|
25
35
|
has,
|
|
26
36
|
/** @readonly */
|
|
37
|
+
complement,
|
|
38
|
+
/** @readonly */
|
|
27
39
|
set,
|
|
28
40
|
/** @readonly */
|
|
29
41
|
unset,
|
|
30
42
|
/** @readonly */
|
|
31
|
-
setRange
|
|
43
|
+
setRange,
|
|
32
44
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { every, map, countdown } = require('../list/module.f.cjs')
|
|
1
2
|
const _ = require('./module.f.cjs')
|
|
2
3
|
|
|
3
4
|
module.exports = {
|
|
@@ -16,7 +17,7 @@ module.exports = {
|
|
|
16
17
|
},
|
|
17
18
|
() => {
|
|
18
19
|
const s = _.set(15)(_.empty)
|
|
19
|
-
if (s !==
|
|
20
|
+
if (s !== 0x8000) { throw s }
|
|
20
21
|
if (_.has(0)(s)) { throw s }
|
|
21
22
|
if (_.has(1)(s)) { throw s }
|
|
22
23
|
if (!_.has(15)(s)) { throw s }
|
|
@@ -37,5 +38,19 @@ module.exports = {
|
|
|
37
38
|
setRange: () => {
|
|
38
39
|
const result = _.setRange([2, 5])(_.empty)
|
|
39
40
|
if (result !== 60) { throw result }
|
|
41
|
+
},
|
|
42
|
+
universe: () => {
|
|
43
|
+
const x = every(map(v => _.has(v)(_.universe))(countdown(16)))
|
|
44
|
+
if (!x) { throw x }
|
|
45
|
+
},
|
|
46
|
+
compliment: {
|
|
47
|
+
empty: () => {
|
|
48
|
+
const r = _.complement(_.empty)
|
|
49
|
+
if (r !== _.universe) { throw r }
|
|
50
|
+
},
|
|
51
|
+
universe: () => {
|
|
52
|
+
const r = _.complement(_.universe)
|
|
53
|
+
if (r !== _.empty) { throw r }
|
|
54
|
+
},
|
|
40
55
|
}
|
|
41
56
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const compare = require(
|
|
2
|
-
const list = require(
|
|
3
|
-
const option = require(
|
|
1
|
+
const compare = require('../function/compare/module.f.cjs')
|
|
2
|
+
const list = require('../list/module.f.cjs')
|
|
3
|
+
const option = require('../option/module.f.cjs')
|
|
4
4
|
const { next } = list
|
|
5
|
+
const { identity } = require('../function/module.f.cjs')
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @template T
|
|
@@ -13,55 +14,74 @@ const { next } = list
|
|
|
13
14
|
* @typedef {(a: T) => (b: T) => compare.Sign} Cmp
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
|
-
/** @typedef {number} Byte */
|
|
17
|
-
|
|
18
17
|
/**
|
|
19
18
|
* @template T
|
|
20
|
-
* @typedef {SortedList<[
|
|
19
|
+
* @typedef {SortedList<[T, number]>} RangeMap
|
|
21
20
|
*/
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
|
-
* @template S
|
|
25
23
|
* @template T
|
|
24
|
+
* @template S
|
|
26
25
|
* @typedef {(state: S) => (a: T) => (b: T) => readonly[option.Option<T>, compare.Sign, S]} ReduceOp
|
|
27
26
|
*/
|
|
28
27
|
|
|
29
28
|
/**
|
|
30
|
-
* @template S
|
|
31
29
|
* @template T
|
|
30
|
+
* @template S
|
|
32
31
|
* @typedef {(state: S) => (tail: list.List<T>) => list.List<T>} TailReduce
|
|
33
32
|
*/
|
|
34
33
|
|
|
35
34
|
/**
|
|
35
|
+
* @template T
|
|
36
36
|
* @template S
|
|
37
|
+
* @typedef {{
|
|
38
|
+
* readonly reduceOp: ReduceOp<T,S>
|
|
39
|
+
* readonly tailReduce: TailReduce<T,S>
|
|
40
|
+
* }} MergeReduce
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/** @type {<T,S>(reduce: MergeReduce<T,S>) => (state: S) => (a: list.List<T>) => (b: list.List<T>) => list.List<T>} */
|
|
44
|
+
const genericMerge = reduce => {
|
|
45
|
+
const { reduceOp, tailReduce } = reduce
|
|
46
|
+
/** @typedef {typeof reduce extends MergeReduce<infer T, infer S> ? [T, S] : never} TS */
|
|
47
|
+
/** @typedef {TS[0]} T */
|
|
48
|
+
/** @typedef {TS[1]} S */
|
|
49
|
+
/** @type {(state: S) => (a: list.List<T>) => (b: list.List<T>) => list.List<T>} */
|
|
50
|
+
const f = state => a => b => () => {
|
|
51
|
+
const aResult = next(a)
|
|
52
|
+
if (aResult === undefined) { return tailReduce(state)(b) }
|
|
53
|
+
const bResult = next(b)
|
|
54
|
+
if (bResult === undefined) { return tailReduce(state)(a) }
|
|
55
|
+
const [first, sign, stateNext] = reduceOp(state)(aResult.first)(bResult.first)
|
|
56
|
+
const aNext = sign === 1 ? a : aResult.tail
|
|
57
|
+
const bNext = sign === -1 ? b : bResult.tail
|
|
58
|
+
const tail = f(stateNext)(aNext)(bNext)
|
|
59
|
+
return first === undefined ? tail : { first, tail }
|
|
60
|
+
}
|
|
61
|
+
return f
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
37
65
|
* @template T
|
|
38
|
-
* @typedef {
|
|
66
|
+
* @typedef {ReduceOp<T, undefined>} CmpReduceOp
|
|
39
67
|
*/
|
|
40
68
|
|
|
41
69
|
/** @type {<T>(cmp: Cmp<T>) => (a: SortedList<T>) => (b: SortedList<T>) => SortedList<T>} */
|
|
42
|
-
const merge = cmp =>
|
|
70
|
+
const merge = cmp => {
|
|
71
|
+
/** @typedef {typeof cmp extends Cmp<infer T> ? T : never} T*/
|
|
72
|
+
/** @type {TailReduce<T, undefined>} */
|
|
73
|
+
const tailReduce = mergeTail
|
|
74
|
+
return genericMerge({ reduceOp: cmpReduce(cmp), tailReduce })(undefined)
|
|
75
|
+
}
|
|
43
76
|
|
|
44
|
-
/** @type {<
|
|
45
|
-
const cmpReduce = cmp =>
|
|
77
|
+
/** @type {<T>(cmp: Cmp<T>) => CmpReduceOp<T>} */
|
|
78
|
+
const cmpReduce = cmp => () => a => b => {
|
|
46
79
|
const sign = cmp(a)(b)
|
|
47
|
-
return [sign === 1 ? b : a, sign,
|
|
80
|
+
return [sign === 1 ? b : a, sign, undefined]
|
|
48
81
|
}
|
|
49
82
|
|
|
50
|
-
/** @type {
|
|
51
|
-
const mergeTail =
|
|
52
|
-
|
|
53
|
-
/** @type {<S,T>(init: S) => (reduce: ReduceOp<S,T>) => (tailReduce: TailReduce<S, T>) => (a: list.List<T>) => (b: list.List<T>) => list.List<T>} */
|
|
54
|
-
const genericMerge = init => reduce => tailReduce => a => b => () => {
|
|
55
|
-
const aResult = next(a)
|
|
56
|
-
if (aResult === undefined) { return tailReduce(init)(b) }
|
|
57
|
-
const bResult = next(b)
|
|
58
|
-
if (bResult === undefined) { return tailReduce(init)(a) }
|
|
59
|
-
const [result, sign, state] = reduce(init)(aResult.first)(bResult.first)
|
|
60
|
-
const aNext = sign === 1 ? a : aResult.tail
|
|
61
|
-
const bNext = sign === -1 ? b : bResult.tail
|
|
62
|
-
const mergeNext = genericMerge(state)(reduce)(tailReduce)(aNext)(bNext)
|
|
63
|
-
return result === undefined ? mergeNext : { first: result, tail: mergeNext }
|
|
64
|
-
}
|
|
83
|
+
/** @type {() => <T>(tail: list.List<T>) => list.List<T>} */
|
|
84
|
+
const mergeTail = () => identity
|
|
65
85
|
|
|
66
86
|
module.exports = {
|
|
67
87
|
/** @readonly */
|
|
@@ -24,16 +24,15 @@ const union = cmp => a => b => toArray(merge(cmp)(a)(b))
|
|
|
24
24
|
const intersect = cmp => a => b => toArray(intersectMerge(cmp)(a)(b))
|
|
25
25
|
|
|
26
26
|
/** @type {<T>(cmp: Cmp<T>) => (a: sortedList.SortedList<T>) => (b: sortedList.SortedList<T>) => sortedList.SortedList<T>} */
|
|
27
|
-
const intersectMerge = cmp => genericMerge(
|
|
27
|
+
const intersectMerge = cmp => genericMerge({ reduceOp: intersectReduce(cmp), tailReduce: intersectTail })(undefined)
|
|
28
28
|
|
|
29
|
-
/** @type {<S
|
|
29
|
+
/** @type {<T,S>(cmp: Cmp<T>) => sortedList.ReduceOp<T,S>} */
|
|
30
30
|
const intersectReduce = cmp => state => a => b => {
|
|
31
31
|
const sign = cmp(a)(b)
|
|
32
32
|
return [sign === 0 ? a : undefined, sign, state]
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
const intersectTail = s => input => undefined
|
|
35
|
+
const intersectTail = () => () => undefined
|
|
37
36
|
|
|
38
37
|
module.exports = {
|
|
39
38
|
/** @readonly */
|