functionalscript 0.0.437 → 0.0.438
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,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functionalscript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.438",
|
|
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
|
}
|
|
@@ -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
|
}
|