functionalscript 0.8.0 → 0.8.1
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/bnf/data/module.f.d.ts +6 -0
- package/bnf/data/module.f.js +57 -4
- package/bnf/data/test.f.d.ts +1 -0
- package/bnf/data/test.f.js +67 -1
- package/ci/module.f.d.ts +3 -0
- package/ci/module.f.js +169 -0
- package/ci/module.js +3 -0
- package/crypto/hmac/module.f.d.ts +5 -4
- package/crypto/hmac/module.f.js +9 -18
- package/crypto/hmac/test.f.d.ts +1 -0
- package/crypto/hmac/test.f.js +16 -8
- package/crypto/prime_field/module.f.d.ts +1 -1
- package/crypto/prime_field/module.f.js +4 -3
- package/crypto/prime_field/test.f.js +13 -13
- package/crypto/rfc6979/module.f.d.ts +15 -0
- package/crypto/rfc6979/module.f.js +98 -0
- package/crypto/rfc6979/test.f.d.ts +10 -0
- package/crypto/rfc6979/test.f.js +490 -0
- package/crypto/secp/module.f.d.ts +4 -4
- package/crypto/secp/module.f.js +1 -1
- package/crypto/secp/test.f.js +8 -8
- package/crypto/sha2/module.f.d.ts +11 -5
- package/crypto/sha2/module.f.js +4 -3
- package/crypto/sha2/test.f.d.ts +4 -1
- package/crypto/sha2/test.f.js +41 -31
- package/crypto/sign/module.f.d.ts +1 -1
- package/crypto/sign/module.f.js +3 -2
- package/dev/tf/all.test.js +9 -1
- package/djs/ast/module.f.d.ts +3 -3
- package/djs/ast/test.f.js +7 -8
- package/djs/parser/module.f.d.ts +3 -3
- package/djs/parser/module.f.js +4 -4
- package/djs/parser/test.f.js +76 -77
- package/djs/serializer/module.f.d.ts +8 -8
- package/djs/serializer/module.f.js +4 -7
- package/djs/serializer/test.f.js +8 -9
- package/djs/tokenizer/module.f.d.ts +2 -2
- package/djs/tokenizer/module.f.js +3 -5
- package/djs/tokenizer/test.f.js +8 -10
- package/djs/transpiler/module.f.d.ts +3 -3
- package/djs/transpiler/module.f.js +2 -0
- package/fsc/bnf.f.d.ts +1 -1
- package/fsc/bnf.f.js +39 -51
- package/fsc/json.f.d.ts +1 -1
- package/fsc/json.f.js +56 -81
- package/fsc/test.f.js +4 -6
- package/fsm/module.f.js +3 -3
- package/fsm/test.f.js +21 -25
- package/html/module.f.js +17 -4
- package/html/test.f.d.ts +7 -0
- package/html/test.f.js +37 -0
- package/issues/031-json.f.d.ts +1 -0
- package/js/tokenizer/module.f.d.ts +4 -4
- package/js/tokenizer/module.f.js +12 -17
- package/js/tokenizer/test.f.js +9 -11
- package/json/module.f.d.ts +6 -6
- package/json/module.f.js +5 -10
- package/json/parser/module.f.d.ts +4 -4
- package/json/parser/module.f.js +7 -4
- package/json/parser/test.f.js +47 -49
- package/json/serializer/module.f.d.ts +6 -6
- package/json/serializer/module.f.js +3 -2
- package/json/serializer/test.f.js +13 -13
- package/json/test.f.js +13 -15
- package/json/tokenizer/module.f.d.ts +4 -4
- package/json/tokenizer/module.f.js +6 -7
- package/json/tokenizer/test.f.js +7 -9
- package/package.json +5 -5
- package/text/ascii/test.f.js +2 -2
- package/text/module.f.d.ts +3 -2
- package/text/module.f.js +2 -2
- package/text/test.f.js +3 -3
- package/text/utf16/test.f.js +2 -2
- package/text/utf8/test.f.js +2 -2
- package/types/array/test.f.js +2 -2
- package/types/bigint/module.f.d.ts +6 -3
- package/types/bigint/module.f.js +12 -11
- package/types/bigint/test.f.d.ts +2 -0
- package/types/bigint/test.f.js +21 -2
- package/types/bit_vec/module.f.d.ts +66 -34
- package/types/bit_vec/module.f.js +97 -32
- package/types/bit_vec/test.f.d.ts +7 -0
- package/types/bit_vec/test.f.js +283 -62
- package/types/btree/find/test.f.js +9 -8
- package/types/btree/remove/test.f.js +4 -4
- package/types/btree/set/test.f.js +4 -4
- package/types/btree/test.f.js +7 -7
- package/types/byte_set/test.f.js +2 -2
- package/types/function/compare/module.f.d.ts +15 -1
- package/types/function/compare/module.f.js +1 -1
- package/types/function/compare/test.f.js +37 -4
- package/types/list/test.f.js +93 -93
- package/types/monoid/module.f.d.ts +4 -4
- package/types/monoid/module.f.js +3 -3
- package/types/monoid/test.f.js +3 -3
- package/types/nominal/module.f.d.ts +5 -0
- package/types/nominal/module.f.js +4 -0
- package/types/nominal/test.f.d.ts +5 -0
- package/types/nominal/test.f.js +53 -0
- package/types/number/module.f.js +2 -2
- package/types/range_map/test.f.js +21 -21
- package/types/sorted_list/test.f.js +10 -10
- package/types/sorted_set/test.f.js +14 -14
- package/types/string/module.f.js +2 -2
- package/types/string_set/module.f.js +3 -3
- package/bnf/func/module.f.d.ts +0 -148
- package/bnf/func/module.f.js +0 -132
- package/bnf/func/test.f.d.ts +0 -12
- package/bnf/func/test.f.js +0 -171
- package/bnf/func/testlib.f.d.ts +0 -25
- package/bnf/func/testlib.f.js +0 -150
- /package/{issues/31-json.f.d.ts → ci/module.d.ts} +0 -0
- /package/issues/{31-json.f.js → 031-json.f.js} +0 -0
package/types/list/test.f.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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
|
|
5
|
+
const str = sequence => stringify(sort)(toArray(sequence));
|
|
6
6
|
const stringifyTest = () => {
|
|
7
|
-
const s =
|
|
7
|
+
const s = str([1, 2, 3]);
|
|
8
8
|
if (s !== '[1,2,3]') {
|
|
9
9
|
throw s;
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
const
|
|
13
|
-
const x =
|
|
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
|
|
19
|
-
const result =
|
|
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
|
|
25
|
-
const result =
|
|
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
|
|
31
|
-
const result =
|
|
32
|
-
const x =
|
|
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
|
|
41
|
-
const result =
|
|
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
|
|
46
|
+
const takeTest = [
|
|
47
47
|
() => {
|
|
48
|
-
const result =
|
|
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 =
|
|
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 =
|
|
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
|
|
66
|
+
const findTest = [
|
|
67
67
|
() => {
|
|
68
|
-
const result =
|
|
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 =
|
|
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
|
|
80
|
+
const takeWhileTest = [
|
|
81
81
|
() => {
|
|
82
|
-
const result =
|
|
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 =
|
|
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
|
|
95
|
-
const result =
|
|
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
|
|
100
|
+
const dropTest = [
|
|
101
101
|
() => {
|
|
102
|
-
const result =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
135
|
+
const result = reduce(addition)(null)([]);
|
|
136
136
|
if (result !== null) {
|
|
137
137
|
throw result;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
];
|
|
141
|
-
const
|
|
141
|
+
const entriesTest = [
|
|
142
142
|
() => {
|
|
143
|
-
const result =
|
|
143
|
+
const result = str(entries([]));
|
|
144
144
|
if (result !== '[]') {
|
|
145
145
|
throw result;
|
|
146
146
|
}
|
|
147
147
|
},
|
|
148
148
|
() => {
|
|
149
|
-
const result =
|
|
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
|
|
155
|
+
const reverseTest = [
|
|
156
156
|
() => {
|
|
157
|
-
const result =
|
|
157
|
+
const result = str(reverse([]));
|
|
158
158
|
if (result !== '[]') {
|
|
159
159
|
throw result;
|
|
160
160
|
}
|
|
161
161
|
},
|
|
162
162
|
() => {
|
|
163
|
-
const result =
|
|
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
|
|
169
|
+
const zipTest = [
|
|
170
170
|
() => {
|
|
171
|
-
const result =
|
|
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 =
|
|
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 =
|
|
184
|
+
const map5 = map((x) => x > 5);
|
|
185
185
|
return [
|
|
186
186
|
() => {
|
|
187
|
-
const result =
|
|
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 =
|
|
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 =
|
|
199
|
+
const result = some(map5([]));
|
|
200
200
|
if (result) {
|
|
201
201
|
throw result;
|
|
202
202
|
}
|
|
203
203
|
},
|
|
204
204
|
() => {
|
|
205
|
-
const result =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
229
|
+
const result = toArray(countdown(n));
|
|
230
230
|
if (result.length !== n) {
|
|
231
231
|
throw result.length;
|
|
232
232
|
}
|
|
233
|
-
const len =
|
|
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 =
|
|
241
|
+
const result = toArray(countdown(n));
|
|
242
242
|
if (result.length !== n) {
|
|
243
243
|
throw result.length;
|
|
244
244
|
}
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
247
|
-
throw
|
|
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 =
|
|
255
|
+
sequence = concat(sequence)([i]);
|
|
256
256
|
}
|
|
257
|
-
const r =
|
|
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 =
|
|
263
|
+
sequence = flat([sequence, [i]]);
|
|
264
264
|
}
|
|
265
|
-
const r =
|
|
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 =
|
|
271
|
+
sequence = flat([sequence, [i]]);
|
|
272
272
|
}
|
|
273
|
-
const a =
|
|
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 =
|
|
279
|
+
sequence = concat([i])(sequence);
|
|
280
280
|
}
|
|
281
|
-
const a =
|
|
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 =
|
|
287
|
+
sequence = flat([[i], sequence]);
|
|
288
288
|
}
|
|
289
|
-
const a =
|
|
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 =
|
|
294
|
+
const result = toArray(countdown(n));
|
|
295
295
|
if (result.length !== n) {
|
|
296
296
|
throw result.length;
|
|
297
297
|
}
|
|
298
|
-
const len =
|
|
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 =
|
|
306
|
+
const result = toArray(countdown(n));
|
|
307
307
|
if (result.length !== n) {
|
|
308
308
|
throw result.length;
|
|
309
309
|
}
|
|
310
|
-
const len =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
369
|
+
const result = isEmpty(() => []);
|
|
370
370
|
if (result !== true) {
|
|
371
371
|
throw result;
|
|
372
372
|
}
|
|
373
373
|
},
|
|
374
374
|
() => {
|
|
375
|
-
const result =
|
|
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 (
|
|
382
|
+
if (length([1, 2, 3]) !== 3) {
|
|
383
383
|
throw 3;
|
|
384
384
|
}
|
|
385
|
-
if (
|
|
385
|
+
if (length(null) !== 0) {
|
|
386
386
|
throw 0;
|
|
387
387
|
}
|
|
388
|
-
if (
|
|
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)(
|
|
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')
|
|
72
|
+
* const resultConcat = repeat(concat)(3n)('ha') // 'hahaha'
|
|
73
73
|
* ```
|
|
74
74
|
*/
|
|
75
|
-
export declare const repeat: <T>({ identity, operation }: Monoid<T>) =>
|
|
75
|
+
export declare const repeat: <T>({ identity, operation }: Monoid<T>) => Fold<bigint, T>;
|
package/types/monoid/module.f.js
CHANGED
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
* operation: a => b => a + b,
|
|
18
18
|
* };
|
|
19
19
|
*
|
|
20
|
-
* const resultAdd = repeat(add)(
|
|
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')
|
|
27
|
+
* const resultConcat = repeat(concat)(3n)('ha') // 'hahaha'
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
export const repeat = ({ identity, operation }) =>
|
|
30
|
+
export const repeat = ({ identity, operation }) => n => a => {
|
|
31
31
|
let ai = a;
|
|
32
32
|
let ni = n;
|
|
33
33
|
let result = identity;
|
package/types/monoid/test.f.js
CHANGED
|
@@ -5,11 +5,11 @@ export default {
|
|
|
5
5
|
identity: 0,
|
|
6
6
|
operation: a => b => a + b,
|
|
7
7
|
};
|
|
8
|
-
const resultAdd = repeat(add)(
|
|
8
|
+
const resultAdd = repeat(add)(10n)(2); // 20
|
|
9
9
|
if (resultAdd !== 20) {
|
|
10
10
|
throw resultAdd;
|
|
11
11
|
}
|
|
12
|
-
const id = repeat(add)(
|
|
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')
|
|
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,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
|
+
};
|
package/types/number/module.f.js
CHANGED
|
@@ -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 {
|
|
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 =
|
|
7
|
+
export const cmp = uCmp;
|
|
8
8
|
const mo = [
|
|
9
9
|
[0x5555_5555, 1],
|
|
10
10
|
[0x3333_3333, 2],
|