functionalscript 0.0.418 → 0.0.419

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.418",
3
+ "version": "0.0.419",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
package/test.f.cjs CHANGED
@@ -5,6 +5,8 @@ require('./types/number/test.f.cjs')
5
5
  require('./types/bigint/module.f.cjs')
6
6
  require('./types/array/test.f.cjs')
7
7
  require('./types/btree/test.f.cjs')
8
+ require('./types/byteSet/test.f.cjs')
9
+ require('./types/nibbleSet/test.f.cjs')
8
10
  require('./sha2/test.f.cjs')
9
11
  require('./json/test.f.cjs')
10
12
  require('./types/string/test.f.cjs')
@@ -0,0 +1,32 @@
1
+ /** @typedef {bigint} byteSet */
2
+ /** @typedef {number} byte */
3
+
4
+ const empty = 0n
5
+
6
+ /** @type {(n: byte) => (s: byteSet) => boolean} */
7
+ const has = n => s => ((s >> BigInt(n)) & 1n) === 1n
8
+
9
+ /** @type {(n: byte) => (s: byteSet) => byteSet} */
10
+ const set = n => s => s | (1n << BigInt(n))
11
+
12
+ /** @type {(n: byte) => (s: byteSet) => byteSet} */
13
+ const unset = n => s => s & ~(1n << BigInt(n))
14
+
15
+ /** @type {(r: readonly[number, number]) => (s: byteSet) => byteSet} */
16
+ const setRange = r => s => s | ((1n << BigInt(r[1] - r[0] + 1)) - 1n << BigInt(r[0]))
17
+
18
+ // how to define FA???
19
+ // const stateA = [init, set] ????
20
+
21
+ module.exports = {
22
+ /** @readonly */
23
+ empty,
24
+ /** @readonly */
25
+ has,
26
+ /** @readonly */
27
+ set,
28
+ /** @readonly */
29
+ unset,
30
+ /** @readonly */
31
+ setRange
32
+ }
@@ -0,0 +1,44 @@
1
+ const _ = require('./module.f.cjs')
2
+
3
+ {
4
+ if (_.has(0)(_.empty)) { throw _.empty }
5
+ if (_.has(1)(_.empty)) { throw _.empty }
6
+ if (_.has(33)(_.empty)) { throw _.empty }
7
+ }
8
+
9
+ {
10
+ const s = _.set(0)(_.empty)
11
+ if (s !== 1n) { throw s }
12
+ if (!_.has(0)(s)) { throw s }
13
+ if (_.has(1)(s)) { throw s }
14
+ if (_.has(33)(s)) { throw s }
15
+ }
16
+
17
+ {
18
+ const s = _.set(33)(_.empty)
19
+ if (s !== 8589934592n) { throw s }
20
+ if (_.has(0)(s)) { throw s }
21
+ if (_.has(1)(s)) { throw s }
22
+ if (!_.has(33)(s)) { throw s }
23
+ }
24
+
25
+ {
26
+ const a = _.set(0)(_.empty)
27
+ const result = _.unset(0)(a)
28
+ if (result !== 0n) { throw result }
29
+ }
30
+
31
+ {
32
+ const a = _.set(255)(_.empty)
33
+ const result = _.unset(255)(a)
34
+ if (result !== 0n) { throw result }
35
+ }
36
+
37
+ {
38
+ const result = _.setRange([2, 5])(_.empty)
39
+ if (result !== 60n) { throw result }
40
+ }
41
+
42
+ module.exports = {
43
+
44
+ }
@@ -0,0 +1,32 @@
1
+ /** @typedef {number} nibbleSet */
2
+ /** @typedef {number} nibble */
3
+
4
+ const empty = 0
5
+
6
+ /** @type {(n: nibble) => (s: nibbleSet) => boolean} */
7
+ const has = n => s => ((s >> n) & 1) === 1
8
+
9
+ /** @type {(n: nibble) => (s: nibbleSet) => nibbleSet} */
10
+ const set = n => s => s | (1 << n)
11
+
12
+ /** @type {(n: nibble) => (s: nibbleSet) => nibbleSet} */
13
+ const unset = n => s => s & ~(1 << n)
14
+
15
+ /** @type {(r: readonly[number, number]) => (s: nibbleSet) => nibbleSet} */
16
+ const setRange = r => s => s | (((1 << (r[1] - r[0] + 1)) - 1 << r[0]))
17
+
18
+ // how to define FA???
19
+ // const stateA = [init, set] ????
20
+
21
+ module.exports = {
22
+ /** @readonly */
23
+ empty,
24
+ /** @readonly */
25
+ has,
26
+ /** @readonly */
27
+ set,
28
+ /** @readonly */
29
+ unset,
30
+ /** @readonly */
31
+ setRange
32
+ }
@@ -0,0 +1,44 @@
1
+ const _ = require('./module.f.cjs')
2
+
3
+ {
4
+ if (_.has(0)(_.empty)) { throw _.empty }
5
+ if (_.has(1)(_.empty)) { throw _.empty }
6
+ if (_.has(15)(_.empty)) { throw _.empty }
7
+ }
8
+
9
+ {
10
+ const s = _.set(0)(_.empty)
11
+ if (s !== 1) { throw s }
12
+ if (!_.has(0)(s)) { throw s }
13
+ if (_.has(1)(s)) { throw s }
14
+ if (_.has(15)(s)) { throw s }
15
+ }
16
+
17
+ {
18
+ const s = _.set(15)(_.empty)
19
+ if (s !== 32768) { throw s }
20
+ if (_.has(0)(s)) { throw s }
21
+ if (_.has(1)(s)) { throw s }
22
+ if (!_.has(15)(s)) { throw s }
23
+ }
24
+
25
+ {
26
+ const a = _.set(0)(_.empty)
27
+ const result = _.unset(0)(a)
28
+ if (result !== 0) { throw result }
29
+ }
30
+
31
+ {
32
+ const a = _.set(15)(_.empty)
33
+ const result = _.unset(15)(a)
34
+ if (result !== 0) { throw result }
35
+ }
36
+
37
+ {
38
+ const result = _.setRange([2, 5])(_.empty)
39
+ if (result !== 60) { throw result }
40
+ }
41
+
42
+ module.exports = {
43
+
44
+ }