functionalscript 0.8.0 → 0.8.2

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.
Files changed (114) hide show
  1. package/bnf/data/module.f.d.ts +6 -0
  2. package/bnf/data/module.f.js +57 -4
  3. package/bnf/data/test.f.d.ts +1 -0
  4. package/bnf/data/test.f.js +67 -1
  5. package/ci/module.f.d.ts +3 -0
  6. package/ci/module.f.js +169 -0
  7. package/ci/module.js +3 -0
  8. package/crypto/hmac/module.f.d.ts +5 -4
  9. package/crypto/hmac/module.f.js +9 -18
  10. package/crypto/hmac/test.f.d.ts +1 -0
  11. package/crypto/hmac/test.f.js +16 -8
  12. package/crypto/secp/module.f.d.ts +14 -11
  13. package/crypto/secp/module.f.js +33 -13
  14. package/crypto/secp/test.f.js +12 -13
  15. package/crypto/sha2/module.f.d.ts +11 -5
  16. package/crypto/sha2/module.f.js +4 -3
  17. package/crypto/sha2/test.f.d.ts +4 -1
  18. package/crypto/sha2/test.f.js +41 -31
  19. package/crypto/sign/module.f.d.ts +17 -4
  20. package/crypto/sign/module.f.js +141 -46
  21. package/crypto/sign/test.f.d.ts +11 -1
  22. package/crypto/sign/test.f.js +631 -1
  23. package/dev/tf/all.test.js +9 -1
  24. package/djs/ast/module.f.d.ts +3 -3
  25. package/djs/ast/test.f.js +7 -8
  26. package/djs/parser/module.f.d.ts +3 -3
  27. package/djs/parser/module.f.js +4 -4
  28. package/djs/parser/test.f.js +76 -77
  29. package/djs/serializer/module.f.d.ts +8 -8
  30. package/djs/serializer/module.f.js +4 -7
  31. package/djs/serializer/test.f.js +8 -9
  32. package/djs/tokenizer/module.f.d.ts +2 -2
  33. package/djs/tokenizer/module.f.js +3 -5
  34. package/djs/tokenizer/test.f.js +8 -10
  35. package/djs/transpiler/module.f.d.ts +3 -3
  36. package/djs/transpiler/module.f.js +2 -0
  37. package/fsc/bnf.f.d.ts +1 -1
  38. package/fsc/bnf.f.js +39 -51
  39. package/fsc/json.f.d.ts +1 -1
  40. package/fsc/json.f.js +56 -81
  41. package/fsc/test.f.js +4 -6
  42. package/fsm/module.f.js +3 -3
  43. package/fsm/test.f.js +21 -25
  44. package/html/module.f.js +17 -4
  45. package/html/test.f.d.ts +7 -0
  46. package/html/test.f.js +37 -0
  47. package/issues/031-json.f.d.ts +1 -0
  48. package/js/tokenizer/module.f.d.ts +4 -4
  49. package/js/tokenizer/module.f.js +12 -17
  50. package/js/tokenizer/test.f.js +9 -11
  51. package/json/module.f.d.ts +6 -6
  52. package/json/module.f.js +5 -10
  53. package/json/parser/module.f.d.ts +4 -4
  54. package/json/parser/module.f.js +7 -4
  55. package/json/parser/test.f.js +47 -49
  56. package/json/serializer/module.f.d.ts +6 -6
  57. package/json/serializer/module.f.js +3 -2
  58. package/json/serializer/test.f.js +13 -13
  59. package/json/test.f.js +13 -15
  60. package/json/tokenizer/module.f.d.ts +4 -4
  61. package/json/tokenizer/module.f.js +6 -7
  62. package/json/tokenizer/test.f.js +7 -9
  63. package/nanvm-lib/tests/vm/test.f.js +1 -1
  64. package/package.json +5 -5
  65. package/path/module.f.d.ts +3 -2
  66. package/text/ascii/test.f.js +2 -2
  67. package/text/module.f.d.ts +3 -2
  68. package/text/module.f.js +2 -2
  69. package/text/test.f.js +3 -3
  70. package/text/utf16/test.f.js +2 -2
  71. package/text/utf8/test.f.js +2 -2
  72. package/types/array/test.f.js +2 -2
  73. package/types/bigint/module.f.d.ts +6 -3
  74. package/types/bigint/module.f.js +12 -11
  75. package/types/bigint/test.f.d.ts +2 -0
  76. package/types/bigint/test.f.js +21 -2
  77. package/types/bit_vec/module.f.d.ts +66 -34
  78. package/types/bit_vec/module.f.js +97 -32
  79. package/types/bit_vec/test.f.d.ts +7 -0
  80. package/types/bit_vec/test.f.js +283 -62
  81. package/types/btree/find/test.f.js +9 -8
  82. package/types/btree/remove/test.f.js +4 -4
  83. package/types/btree/set/test.f.js +4 -4
  84. package/types/btree/test.f.js +7 -7
  85. package/types/byte_set/test.f.js +2 -2
  86. package/types/function/compare/module.f.d.ts +15 -1
  87. package/types/function/compare/module.f.js +1 -1
  88. package/types/function/compare/test.f.js +37 -4
  89. package/types/list/test.f.js +93 -93
  90. package/types/monoid/module.f.d.ts +4 -4
  91. package/types/monoid/module.f.js +3 -3
  92. package/types/monoid/test.f.js +3 -3
  93. package/types/nominal/module.f.d.ts +5 -0
  94. package/types/nominal/module.f.js +4 -0
  95. package/types/nominal/test.f.d.ts +5 -0
  96. package/types/nominal/test.f.js +53 -0
  97. package/types/number/module.f.js +2 -2
  98. package/{crypto → types}/prime_field/module.f.d.ts +2 -2
  99. package/{crypto → types}/prime_field/module.f.js +5 -4
  100. package/{crypto → types}/prime_field/test.f.js +13 -13
  101. package/types/range_map/test.f.js +21 -21
  102. package/types/sorted_list/test.f.js +10 -10
  103. package/types/sorted_set/test.f.js +14 -14
  104. package/types/string/module.f.js +2 -2
  105. package/types/string_set/module.f.js +3 -3
  106. package/bnf/func/module.f.d.ts +0 -148
  107. package/bnf/func/module.f.js +0 -132
  108. package/bnf/func/test.f.d.ts +0 -12
  109. package/bnf/func/test.f.js +0 -171
  110. package/bnf/func/testlib.f.d.ts +0 -25
  111. package/bnf/func/testlib.f.js +0 -150
  112. /package/{issues/31-json.f.d.ts → ci/module.d.ts} +0 -0
  113. /package/issues/{31-json.f.js → 031-json.f.js} +0 -0
  114. /package/{crypto → types}/prime_field/test.f.d.ts +0 -0
@@ -1,35 +1,35 @@
1
- import * as _ from "./module.f.js";
2
- import * as json from "../../json/module.f.js";
1
+ import { length, concat, countdown, cycle, drop, dropWhile, entries, every, filter, find, flat, flatMap, map, next, reduce, reverse, scan, some, take, takeWhile, toArray, zip, first, filterMap, isEmpty, equal } from "./module.f.js";
2
+ import { stringify } from "../../json/module.f.js";
3
3
  import { sort } from "../object/module.f.js";
4
4
  import { addition, strictEqual, reduceToScan } from "../function/operator/module.f.js";
5
- const stringify = sequence => json.stringify(sort)(_.toArray(sequence));
5
+ const str = sequence => stringify(sort)(toArray(sequence));
6
6
  const stringifyTest = () => {
7
- const s = stringify([1, 2, 3]);
7
+ const s = str([1, 2, 3]);
8
8
  if (s !== '[1,2,3]') {
9
9
  throw s;
10
10
  }
11
11
  };
12
- const cycle = () => {
13
- const x = stringify(_.toArray(_.take(10)(_.cycle([1, 2, 3]))));
12
+ const cycleTest = () => {
13
+ const x = str(toArray(take(10)(cycle([1, 2, 3]))));
14
14
  if (x !== '[1,2,3,1,2,3,1,2,3,1]') {
15
15
  throw x;
16
16
  }
17
17
  };
18
- const countdown = () => {
19
- const result = stringify(_.countdown(10));
18
+ const countdownTest = () => {
19
+ const result = str(countdown(10));
20
20
  if (result !== '[9,8,7,6,5,4,3,2,1,0]') {
21
21
  throw result;
22
22
  }
23
23
  };
24
- const flat = () => {
25
- const result = stringify(_.flat([[1, 2, 3], [4, 5], [6], [], [7, 8, 9]]));
24
+ const flatTest = () => {
25
+ const result = str(flat([[1, 2, 3], [4, 5], [6], [], [7, 8, 9]]));
26
26
  if (result !== '[1,2,3,4,5,6,7,8,9]') {
27
27
  throw result;
28
28
  }
29
29
  };
30
- const concat = () => {
31
- const result = _.concat([1])([2]);
32
- const x = _.next(result);
30
+ const concatTest = () => {
31
+ const result = concat([1])([2]);
32
+ const x = next(result);
33
33
  if (x === null) {
34
34
  throw x;
35
35
  }
@@ -37,81 +37,81 @@ const concat = () => {
37
37
  throw x;
38
38
  }
39
39
  };
40
- const flatMap = () => {
41
- const result = stringify(_.flatMap((x) => [x, x * 2, x * 3])([0, 1, 2, 3]));
40
+ const flatMapTest = () => {
41
+ const result = str(flatMap((x) => [x, x * 2, x * 3])([0, 1, 2, 3]));
42
42
  if (result !== '[0,0,0,1,2,3,2,4,6,3,6,9]') {
43
43
  throw result;
44
44
  }
45
45
  };
46
- const take = [
46
+ const takeTest = [
47
47
  () => {
48
- const result = stringify(_.take(3)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
48
+ const result = str(take(3)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
49
49
  if (result !== '[1,2,3]') {
50
50
  throw result;
51
51
  }
52
52
  },
53
53
  () => {
54
- const result = stringify(_.take(20)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
54
+ const result = str(take(20)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
55
55
  if (result !== '[1,2,3,4,5,6,7,8,9]') {
56
56
  throw result;
57
57
  }
58
58
  },
59
59
  () => {
60
- const result = stringify(_.take(0)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
60
+ const result = str(take(0)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
61
61
  if (result !== '[]') {
62
62
  throw result;
63
63
  }
64
64
  }
65
65
  ];
66
- const find = [
66
+ const findTest = [
67
67
  () => {
68
- const result = _.find(null)((x) => x % 2 === 0)([1, 3, 5, 7]);
68
+ const result = find(null)((x) => x % 2 === 0)([1, 3, 5, 7]);
69
69
  if (result !== null) {
70
70
  throw result;
71
71
  }
72
72
  },
73
73
  () => {
74
- const result = _.find(null)((x) => x % 2 === 0)([1, 2, 3, 4]);
74
+ const result = find(null)((x) => x % 2 === 0)([1, 2, 3, 4]);
75
75
  if (result !== 2) {
76
76
  throw result;
77
77
  }
78
78
  }
79
79
  ];
80
- const takeWhile = [
80
+ const takeWhileTest = [
81
81
  () => {
82
- const result = stringify(_.takeWhile((x) => x < 10)([1, 2, 3, 4, 5, 10, 11]));
82
+ const result = str(takeWhile((x) => x < 10)([1, 2, 3, 4, 5, 10, 11]));
83
83
  if (result !== '[1,2,3,4,5]') {
84
84
  throw result;
85
85
  }
86
86
  },
87
87
  () => {
88
- const result = stringify(_.takeWhile((x) => x < 6)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
88
+ const result = str(takeWhile((x) => x < 6)([1, 2, 3, 4, 5, 6, 7, 8, 9]));
89
89
  if (result !== '[1,2,3,4,5]') {
90
90
  throw result;
91
91
  }
92
92
  }
93
93
  ];
94
- const dropWhile = () => {
95
- const result = stringify(_.dropWhile((x) => x < 10)([1, 2, 3, 4, 5, 10, 11]));
94
+ const dropWhileTest = () => {
95
+ const result = str(dropWhile((x) => x < 10)([1, 2, 3, 4, 5, 10, 11]));
96
96
  if (result !== '[10,11]') {
97
97
  throw result;
98
98
  }
99
99
  };
100
- const drop = [
100
+ const dropTest = [
101
101
  () => {
102
- const result = stringify(_.drop(3)([1, 2, 3, 4, 5, 10, 11]));
102
+ const result = str(drop(3)([1, 2, 3, 4, 5, 10, 11]));
103
103
  if (result !== '[4,5,10,11]') {
104
104
  throw result;
105
105
  }
106
106
  },
107
107
  () => {
108
- const result = stringify(_.drop(0)([1, 2, 3, 4, 5, 10, 11]));
108
+ const result = str(drop(0)([1, 2, 3, 4, 5, 10, 11]));
109
109
  if (result !== '[1,2,3,4,5,10,11]') {
110
110
  throw result;
111
111
  }
112
112
  },
113
113
  () => {
114
- const result = stringify(_.drop(10)([1, 2, 3, 4, 5, 10, 11]));
114
+ const result = str(drop(10)([1, 2, 3, 4, 5, 10, 11]));
115
115
  if (result !== '[]') {
116
116
  throw result;
117
117
  }
@@ -120,101 +120,101 @@ const drop = [
120
120
  const additionTests = [
121
121
  () => {
122
122
  const op = reduceToScan(addition);
123
- const result = stringify(_.scan(op)([2, 3, 4, 5]));
123
+ const result = str(scan(op)([2, 3, 4, 5]));
124
124
  if (result !== '[2,5,9,14]') {
125
125
  throw result;
126
126
  }
127
127
  },
128
128
  () => {
129
- const result = _.reduce(addition)(null)([2, 3, 4, 5]);
129
+ const result = reduce(addition)(null)([2, 3, 4, 5]);
130
130
  if (result !== 14) {
131
131
  throw result;
132
132
  }
133
133
  },
134
134
  () => {
135
- const result = _.reduce(addition)(null)([]);
135
+ const result = reduce(addition)(null)([]);
136
136
  if (result !== null) {
137
137
  throw result;
138
138
  }
139
139
  }
140
140
  ];
141
- const entries = [
141
+ const entriesTest = [
142
142
  () => {
143
- const result = stringify(_.entries([]));
143
+ const result = str(entries([]));
144
144
  if (result !== '[]') {
145
145
  throw result;
146
146
  }
147
147
  },
148
148
  () => {
149
- const result = stringify(_.entries(['hello', 'world']));
149
+ const result = str(entries(['hello', 'world']));
150
150
  if (result !== '[[0,"hello"],[1,"world"]]') {
151
151
  throw result;
152
152
  }
153
153
  }
154
154
  ];
155
- const reverse = [
155
+ const reverseTest = [
156
156
  () => {
157
- const result = stringify(_.reverse([]));
157
+ const result = str(reverse([]));
158
158
  if (result !== '[]') {
159
159
  throw result;
160
160
  }
161
161
  },
162
162
  () => {
163
- const result = stringify(_.reverse([1, 2, 3, 4, 5]));
163
+ const result = str(reverse([1, 2, 3, 4, 5]));
164
164
  if (result !== '[5,4,3,2,1]') {
165
165
  throw result;
166
166
  }
167
167
  }
168
168
  ];
169
- const zip = [
169
+ const zipTest = [
170
170
  () => {
171
- const result = stringify(_.zip([0, 1, 2])(['a', 'b', 'c', 'd']));
171
+ const result = str(zip([0, 1, 2])(['a', 'b', 'c', 'd']));
172
172
  if (result !== '[[0,"a"],[1,"b"],[2,"c"]]') {
173
173
  throw result;
174
174
  }
175
175
  },
176
176
  () => {
177
- const result = stringify(_.zip([0, 1, 2])(['a', 'b']));
177
+ const result = str(zip([0, 1, 2])(['a', 'b']));
178
178
  if (result !== '[[0,"a"],[1,"b"]]') {
179
179
  throw result;
180
180
  }
181
181
  }
182
182
  ];
183
183
  const logic = () => {
184
- const map5 = _.map((x) => x > 5);
184
+ const map5 = map((x) => x > 5);
185
185
  return [
186
186
  () => {
187
- const result = _.some(map5([0, 1, 7]));
187
+ const result = some(map5([0, 1, 7]));
188
188
  if (!result) {
189
189
  throw result;
190
190
  }
191
191
  },
192
192
  () => {
193
- const result = _.some(map5([0, 1, 4]));
193
+ const result = some(map5([0, 1, 4]));
194
194
  if (result) {
195
195
  throw result;
196
196
  }
197
197
  },
198
198
  () => {
199
- const result = _.some(map5([]));
199
+ const result = some(map5([]));
200
200
  if (result) {
201
201
  throw result;
202
202
  }
203
203
  },
204
204
  () => {
205
- const result = _.every(map5([0, 1, 7]));
205
+ const result = every(map5([0, 1, 7]));
206
206
  if (result) {
207
207
  throw result;
208
208
  }
209
209
  },
210
210
  () => {
211
- const result = _.every(map5([6, 11, 7]));
211
+ const result = every(map5([6, 11, 7]));
212
212
  if (!result) {
213
213
  throw result;
214
214
  }
215
215
  },
216
216
  () => {
217
- const result = _.every(map5([]));
217
+ const result = every(map5([]));
218
218
  if (!result) {
219
219
  throw result;
220
220
  }
@@ -226,11 +226,11 @@ const stress = () => ({
226
226
  toArray: () => {
227
227
  // 200_000_000 is too much
228
228
  const n = 100_000_000;
229
- const result = _.toArray(_.countdown(n));
229
+ const result = toArray(countdown(n));
230
230
  if (result.length !== n) {
231
231
  throw result.length;
232
232
  }
233
- const len = _.length(_.filter((x) => x > n)(result));
233
+ const len = length(filter((x) => x > n)(result));
234
234
  if (len !== 0) {
235
235
  throw len;
236
236
  }
@@ -238,13 +238,13 @@ const stress = () => ({
238
238
  first: () => {
239
239
  // 100_000_000 is too much
240
240
  const n = 50_000_000;
241
- const result = _.toArray(_.countdown(n));
241
+ const result = toArray(countdown(n));
242
242
  if (result.length !== n) {
243
243
  throw result.length;
244
244
  }
245
- const first = _.first(null)(result);
246
- if (first !== n - 1) {
247
- throw first;
245
+ const f = first(null)(result);
246
+ if (f !== n - 1) {
247
+ throw f;
248
248
  }
249
249
  },
250
250
  concatBack: () => {
@@ -252,50 +252,50 @@ const stress = () => ({
252
252
  // 20_000_000 is too much
253
253
  // 10_000_000 is too much for Deno 1
254
254
  for (let i = 0; i < 5_000_000; ++i) {
255
- sequence = _.concat(sequence)([i]);
255
+ sequence = concat(sequence)([i]);
256
256
  }
257
- const r = _.toArray(sequence);
257
+ const r = toArray(sequence);
258
258
  },
259
259
  flatToArray: () => {
260
260
  let sequence = [];
261
261
  // 4_000_000 is too much
262
262
  for (let i = 0; i < 2_000_000; ++i) {
263
- sequence = _.flat([sequence, [i]]);
263
+ sequence = flat([sequence, [i]]);
264
264
  }
265
- const r = _.toArray(sequence);
265
+ const r = toArray(sequence);
266
266
  },
267
267
  flatNext: () => {
268
268
  let sequence = [];
269
269
  // 4_000_000 is too much
270
270
  for (let i = 0; i < 2_000_000; ++i) {
271
- sequence = _.flat([sequence, [i]]);
271
+ sequence = flat([sequence, [i]]);
272
272
  }
273
- const a = _.next(sequence);
273
+ const a = next(sequence);
274
274
  },
275
275
  concatFront: () => {
276
276
  let sequence = [];
277
277
  // 20_000_000 is too much
278
278
  for (let i = 0; i < 10_000_000; ++i) {
279
- sequence = _.concat([i])(sequence);
279
+ sequence = concat([i])(sequence);
280
280
  }
281
- const a = _.next(sequence);
281
+ const a = next(sequence);
282
282
  },
283
283
  flatFront: () => {
284
284
  let sequence = [];
285
285
  // 10_000_000 is too much
286
286
  for (let i = 0; i < 5_000_000; ++i) {
287
- sequence = _.flat([[i], sequence]);
287
+ sequence = flat([[i], sequence]);
288
288
  }
289
- const a = _.next(sequence);
289
+ const a = next(sequence);
290
290
  },
291
291
  filterMap: () => {
292
292
  // 100_000_000 is too much
293
293
  const n = 50_000_000;
294
- const result = _.toArray(_.countdown(n));
294
+ const result = toArray(countdown(n));
295
295
  if (result.length !== n) {
296
296
  throw result.length;
297
297
  }
298
- const len = _.length(_.filterMap(() => null)(result));
298
+ const len = length(filterMap(() => null)(result));
299
299
  if (len !== 0) {
300
300
  throw len;
301
301
  }
@@ -303,11 +303,11 @@ const stress = () => ({
303
303
  dropWhile: () => {
304
304
  // 50_000_000 is too much
305
305
  const n = 20_000_000;
306
- const result = _.toArray(_.countdown(n));
306
+ const result = toArray(countdown(n));
307
307
  if (result.length !== n) {
308
308
  throw result.length;
309
309
  }
310
- const len = _.length(_.dropWhile(() => true)(result));
310
+ const len = length(dropWhile(() => true)(result));
311
311
  if (len !== 0) {
312
312
  throw len;
313
313
  }
@@ -315,7 +315,7 @@ const stress = () => ({
315
315
  reverse: () => {
316
316
  // 10_000_000 is too much
317
317
  const n = 5_000_000;
318
- const result = _.toArray(_.reverse(_.countdown(n)));
318
+ const result = toArray(reverse(countdown(n)));
319
319
  if (result.length !== n) {
320
320
  throw result.length;
321
321
  }
@@ -323,42 +323,42 @@ const stress = () => ({
323
323
  });
324
324
  export default {
325
325
  stringifyTest,
326
- cycle,
327
- countdown,
328
- flat,
329
- concat,
330
- flatMap,
331
- take,
332
- find,
333
- takeWhile,
334
- dropWhile,
335
- drop,
326
+ cycle: cycleTest,
327
+ countdown: countdownTest,
328
+ flat: flatTest,
329
+ concat: concatTest,
330
+ flatMap: flatMapTest,
331
+ take: takeTest,
332
+ find: findTest,
333
+ takeWhile: takeWhileTest,
334
+ dropWhile: dropWhileTest,
335
+ drop: dropTest,
336
336
  additionTests,
337
- entries,
338
- reverse,
339
- zip,
337
+ entries: entriesTest,
338
+ reverse: reverseTest,
339
+ zip: zipTest,
340
340
  logic,
341
341
  strictEqual: [
342
342
  () => {
343
- const result = _.equal(strictEqual)([1])([2, 3]);
343
+ const result = equal(strictEqual)([1])([2, 3]);
344
344
  if (result) {
345
345
  throw result;
346
346
  }
347
347
  },
348
348
  () => {
349
- const result = _.equal(strictEqual)([1, 3])([1]);
349
+ const result = equal(strictEqual)([1, 3])([1]);
350
350
  if (result) {
351
351
  throw result;
352
352
  }
353
353
  },
354
354
  () => {
355
- const result = _.equal(strictEqual)([15, 78])([15, 78]);
355
+ const result = equal(strictEqual)([15, 78])([15, 78]);
356
356
  if (!result) {
357
357
  throw result;
358
358
  }
359
359
  },
360
360
  () => {
361
- const result = _.equal(strictEqual)([])([]);
361
+ const result = equal(strictEqual)([])([]);
362
362
  if (!result) {
363
363
  throw result;
364
364
  }
@@ -366,26 +366,26 @@ export default {
366
366
  ],
367
367
  isEmpty: [
368
368
  () => {
369
- const result = _.isEmpty(() => []);
369
+ const result = isEmpty(() => []);
370
370
  if (result !== true) {
371
371
  throw result;
372
372
  }
373
373
  },
374
374
  () => {
375
- const result = _.isEmpty(() => [2]);
375
+ const result = isEmpty(() => [2]);
376
376
  if (result !== false) {
377
377
  throw result;
378
378
  }
379
379
  }
380
380
  ],
381
381
  length: () => {
382
- if (_.length([1, 2, 3]) !== 3) {
382
+ if (length([1, 2, 3]) !== 3) {
383
383
  throw 3;
384
384
  }
385
- if (_.length(null) !== 0) {
385
+ if (length(null) !== 0) {
386
386
  throw 0;
387
387
  }
388
- if (_.length(_.flat([[1, 3], null, () => [3], _.concat([12])([4, 89])])) !== 6) {
388
+ if (length(flat([[1, 3], null, () => [3], concat([12])([4, 89])])) !== 6) {
389
389
  throw 6;
390
390
  }
391
391
  },
@@ -1,4 +1,4 @@
1
- import type { Reduce } from '../function/operator/module.f.ts';
1
+ import type { Fold, Reduce } from '../function/operator/module.f.ts';
2
2
  /**
3
3
  * Represents a monoid, an algebraic structure with a binary operation
4
4
  * and an identity (neutral) element.
@@ -62,14 +62,14 @@ export type Monoid<T> = {
62
62
  * operation: a => b => a + b,
63
63
  * };
64
64
  *
65
- * const resultAdd = repeat(add)(2)(10n) // 20
65
+ * const resultAdd = repeat(add)(10n)(2) // 20
66
66
  *
67
67
  * const concat: Monoid<string> = {
68
68
  * identity: '',
69
69
  * operation: a => b => a + b,
70
70
  * };
71
71
  *
72
- * const resultConcat = repeat(concat)('ha')(3n) // 'hahaha'
72
+ * const resultConcat = repeat(concat)(3n)('ha') // 'hahaha'
73
73
  * ```
74
74
  */
75
- export declare const repeat: <T>({ identity, operation }: Monoid<T>) => (a: T) => (n: bigint) => T;
75
+ export declare const repeat: <T>({ identity, operation }: Monoid<T>) => Fold<bigint, T>;
@@ -17,17 +17,17 @@
17
17
  * operation: a => b => a + b,
18
18
  * };
19
19
  *
20
- * const resultAdd = repeat(add)(2)(10n) // 20
20
+ * const resultAdd = repeat(add)(10n)(2) // 20
21
21
  *
22
22
  * const concat: Monoid<string> = {
23
23
  * identity: '',
24
24
  * operation: a => b => a + b,
25
25
  * };
26
26
  *
27
- * const resultConcat = repeat(concat)('ha')(3n) // 'hahaha'
27
+ * const resultConcat = repeat(concat)(3n)('ha') // 'hahaha'
28
28
  * ```
29
29
  */
30
- export const repeat = ({ identity, operation }) => (a) => (n) => {
30
+ export const repeat = ({ identity, operation }) => n => a => {
31
31
  let ai = a;
32
32
  let ni = n;
33
33
  let result = identity;
@@ -5,11 +5,11 @@ export default {
5
5
  identity: 0,
6
6
  operation: a => b => a + b,
7
7
  };
8
- const resultAdd = repeat(add)(2)(10n); // 20
8
+ const resultAdd = repeat(add)(10n)(2); // 20
9
9
  if (resultAdd !== 20) {
10
10
  throw resultAdd;
11
11
  }
12
- const id = repeat(add)(42)(0n);
12
+ const id = repeat(add)(0n)(42);
13
13
  if (id !== 0) {
14
14
  throw id;
15
15
  }
@@ -19,7 +19,7 @@ export default {
19
19
  identity: '',
20
20
  operation: a => b => a + b,
21
21
  };
22
- const resultConcat = repeat(concat)('ha')(3n); // 'hahaha'
22
+ const resultConcat = repeat(concat)(3n)('ha'); // 'hahaha'
23
23
  if (resultConcat !== 'hahaha') {
24
24
  throw resultConcat;
25
25
  }
@@ -0,0 +1,5 @@
1
+ export type Nominal<N extends string, R extends string, B> = symbol & {
2
+ [k in N]: readonly [R, B];
3
+ };
4
+ export declare const asNominal: <N extends string, R extends string, B>(b: B) => Nominal<N, R, B>;
5
+ export declare const asBase: <T extends string, R extends string, B>(n: Nominal<T, R, B>) => B;
@@ -0,0 +1,4 @@
1
+ /// note: It should compiles into `identity` and no-ops at runtime.
2
+ export const asNominal = (b) => b;
3
+ /// note: It should compiles into `identity` and no-ops at runtime.
4
+ export const asBase = (n) => n;
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ pre: () => void;
3
+ nominal: () => void;
4
+ };
5
+ export default _default;
@@ -0,0 +1,53 @@
1
+ import { asBase, asNominal } from "./module.f.js";
2
+ export default {
3
+ pre: () => {
4
+ const strA = asNominal(7560413859n); // "¢£"
5
+ const strB = asNominal(7560413860n); // "¢¤"
6
+ if (strA === strB) {
7
+ throw [strA, strB];
8
+ }
9
+ // // TypeScript compilation error.
10
+ // const x1 = strA > strB
11
+ //
12
+ {
13
+ const a = { value: 1 };
14
+ const b = { value: 2 };
15
+ // No Compile-time error
16
+ if (a < b) { }
17
+ }
18
+ {
19
+ const x = { _brand: 'NoCompare' };
20
+ // No Error
21
+ if (x < x) { }
22
+ }
23
+ {
24
+ const a = {};
25
+ const b = {};
26
+ // No Error
27
+ a < b;
28
+ }
29
+ {
30
+ const a = undefined;
31
+ const b = undefined;
32
+ // a < b; // TS2469: Operator '<' cannot be applied to type 'symbol'.
33
+ }
34
+ },
35
+ nominal: () => {
36
+ const userIdA = asNominal(123);
37
+ const userIdB = asNominal(456);
38
+ if (userIdA === userIdB) {
39
+ throw [userIdA, userIdB];
40
+ }
41
+ const to = asBase;
42
+ const to2 = asBase;
43
+ const userId2A = asNominal(123);
44
+ const userId2B = asNominal(456);
45
+ if (userId2A === userId2B) {
46
+ throw [userId2A, userId2B];
47
+ }
48
+ // if (userIdA === userId2A) { throw [userIdA, userId2A] } // compilation error
49
+ const n1 = to(userIdA);
50
+ const n2 = to2(userId2A);
51
+ // const x = to(userId2A) // compilation error
52
+ }
53
+ };
@@ -1,10 +1,10 @@
1
1
  import { reduce } from "../list/module.f.js";
2
2
  import { addition, min as minOp, max as maxOp } from "../function/operator/module.f.js";
3
- import { unsafeCmp } from "../function/compare/module.f.js";
3
+ import { cmp as uCmp } from "../function/compare/module.f.js";
4
4
  export const sum = reduce(addition)(0);
5
5
  export const min = reduce(minOp)(null);
6
6
  export const max = reduce(maxOp)(null);
7
- export const cmp = unsafeCmp;
7
+ export const cmp = uCmp;
8
8
  const mo = [
9
9
  [0x5555_5555, 1],
10
10
  [0x3333_3333, 2],
@@ -1,4 +1,4 @@
1
- import type { Unary, Reduce } from '../../types/bigint/module.f.ts';
1
+ import type { Unary, Reduce } from '../bigint/module.f.ts';
2
2
  /**
3
3
  * A type representing a prime field and its associated operations.
4
4
  */
@@ -37,4 +37,4 @@ export declare const prime_field: (p: bigint) => PrimeField;
37
37
  * if (root !== 2n) { throw root }
38
38
  * ```
39
39
  */
40
- export declare const sqrt: ({ p, mul, pow }: PrimeField) => (a: bigint) => bigint | null;
40
+ export declare const sqrt: ({ p, pow, pow2 }: PrimeField) => (a: bigint) => bigint | null;
@@ -1,4 +1,4 @@
1
- import { repeat } from "../../types/monoid/module.f.js";
1
+ import { repeat } from "../monoid/module.f.js";
2
2
  /**
3
3
  * Creates a prime field with the specified prime modulus and associated operations.
4
4
  *
@@ -65,13 +65,14 @@ export const prime_field = (p) => {
65
65
  * if (root !== 2n) { throw root }
66
66
  * ```
67
67
  */
68
- export const sqrt = ({ p, mul, pow }) => {
68
+ export const sqrt = ({ p, pow, pow2 }) => {
69
69
  if ((p & 3n) !== 3n) {
70
70
  throw 'sqrt';
71
71
  }
72
72
  const sqrt_k = (p + 1n) >> 2n;
73
+ const psk = pow(sqrt_k);
73
74
  return a => {
74
- const result = pow(a)(sqrt_k);
75
- return mul(result)(result) === a ? result : null;
75
+ const result = psk(a);
76
+ return pow2(result) === a ? result : null;
76
77
  };
77
78
  };