@nlozgachev/pipelined 0.58.0 → 0.59.0
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/README.md +4 -4
- package/dist/{chunk-JSG7SFXS.js → composition.mjs} +43 -18
- package/dist/{chunk-VYHAA4KO.js → core.mjs} +28 -6
- package/dist/{chunk-FVWJMPQI.js → data.mjs} +261 -7
- package/dist/index.mjs +4432 -0
- package/dist/{chunk-OIIOGDHK.js → types.mjs} +2 -3
- package/package.json +41 -21
- package/dist/composition.js +0 -65
- package/dist/core.js +0 -49
- package/dist/data.js +0 -22
- package/dist/index.js +0 -136
- package/dist/types.js +0 -10
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4432 @@
|
|
|
1
|
+
// src/Composition/compose.ts
|
|
2
|
+
function compose(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9) {
|
|
3
|
+
const len = arguments.length;
|
|
4
|
+
switch (len) {
|
|
5
|
+
case 1: {
|
|
6
|
+
return f0;
|
|
7
|
+
}
|
|
8
|
+
case 2: {
|
|
9
|
+
return function() {
|
|
10
|
+
return f0(f1.apply(this, arguments));
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
case 3: {
|
|
14
|
+
return function() {
|
|
15
|
+
return f0(f1(f2.apply(this, arguments)));
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
case 4: {
|
|
19
|
+
return function() {
|
|
20
|
+
return f0(f1(f2(f3.apply(this, arguments))));
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
case 5: {
|
|
24
|
+
return function() {
|
|
25
|
+
return f0(f1(f2(f3(f4.apply(this, arguments)))));
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
case 6: {
|
|
29
|
+
return function() {
|
|
30
|
+
return f0(f1(f2(f3(f4(f5.apply(this, arguments))))));
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
case 7: {
|
|
34
|
+
return function() {
|
|
35
|
+
return f0(f1(f2(f3(f4(f5(f6.apply(this, arguments)))))));
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
case 8: {
|
|
39
|
+
return function() {
|
|
40
|
+
return f0(f1(f2(f3(f4(f5(f6(f7.apply(this, arguments))))))));
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
case 9: {
|
|
44
|
+
return function() {
|
|
45
|
+
return f0(f1(f2(f3(f4(f5(f6(f7(f8.apply(this, arguments)))))))));
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
case 10: {
|
|
49
|
+
return function() {
|
|
50
|
+
return f0(f1(f2(f3(f4(f5(f6(f7(f8(f9.apply(this, arguments))))))))));
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/Composition/converge.ts
|
|
57
|
+
function converge(f, transformers) {
|
|
58
|
+
return (a) => f(...transformers.map((t) => t(a)));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/Composition/curry.ts
|
|
62
|
+
var curry = (f) => (a) => (b) => f(a, b);
|
|
63
|
+
var curry3 = (f) => (a) => (b) => (c) => f(a, b, c);
|
|
64
|
+
var curry4 = (f) => (a) => (b) => (c) => (d) => f(a, b, c, d);
|
|
65
|
+
|
|
66
|
+
// src/Composition/flip.ts
|
|
67
|
+
var flip = (f) => (b) => (a) => f(a)(b);
|
|
68
|
+
|
|
69
|
+
// src/Composition/flow.ts
|
|
70
|
+
function flow(ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
|
|
71
|
+
const len = arguments.length;
|
|
72
|
+
switch (len) {
|
|
73
|
+
case 0: {
|
|
74
|
+
return function(...args) {
|
|
75
|
+
return args[0];
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
case 1: {
|
|
79
|
+
return ab;
|
|
80
|
+
}
|
|
81
|
+
case 2: {
|
|
82
|
+
return function() {
|
|
83
|
+
return bc(ab.apply(this, arguments));
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
case 3: {
|
|
87
|
+
return function() {
|
|
88
|
+
return cd(bc(ab.apply(this, arguments)));
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
case 4: {
|
|
92
|
+
return function() {
|
|
93
|
+
return de(cd(bc(ab.apply(this, arguments))));
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
case 5: {
|
|
97
|
+
return function() {
|
|
98
|
+
return ef(de(cd(bc(ab.apply(this, arguments)))));
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
case 6: {
|
|
102
|
+
return function() {
|
|
103
|
+
return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
case 7: {
|
|
107
|
+
return function() {
|
|
108
|
+
return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
case 8: {
|
|
112
|
+
return function() {
|
|
113
|
+
return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
case 9: {
|
|
117
|
+
return function() {
|
|
118
|
+
return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
case 10: {
|
|
122
|
+
return function() {
|
|
123
|
+
return jk(ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))))));
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
var when = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
|
|
129
|
+
var unless = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
|
|
130
|
+
var either = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
|
|
131
|
+
var struct = (fields) => (a) => {
|
|
132
|
+
const result = {};
|
|
133
|
+
for (const key of Object.keys(fields)) {
|
|
134
|
+
result[key] = fields[key](a);
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
function safe(...fns) {
|
|
139
|
+
return (a) => {
|
|
140
|
+
let result = a;
|
|
141
|
+
if (result === null || result === void 0) {
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
for (const fn of fns) {
|
|
145
|
+
result = fn(result);
|
|
146
|
+
if (result === null || result === void 0) {
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function async(...fns) {
|
|
154
|
+
return async (a) => {
|
|
155
|
+
let result = await a;
|
|
156
|
+
for (const fn of fns) {
|
|
157
|
+
result = await fn(result);
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
flow.when = when;
|
|
163
|
+
flow.unless = unless;
|
|
164
|
+
flow.either = either;
|
|
165
|
+
flow.struct = struct;
|
|
166
|
+
flow.safe = safe;
|
|
167
|
+
flow.async = async;
|
|
168
|
+
flow.try = (f, onError) => (a) => {
|
|
169
|
+
try {
|
|
170
|
+
return f(a);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return onError(error, a);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// src/Composition/fn.ts
|
|
177
|
+
var identity = (a) => a;
|
|
178
|
+
var constant = (a) => () => a;
|
|
179
|
+
var constTrue = () => true;
|
|
180
|
+
var constFalse = () => false;
|
|
181
|
+
var constNull = () => null;
|
|
182
|
+
var constUndefined = () => void 0;
|
|
183
|
+
var constVoid = () => {
|
|
184
|
+
};
|
|
185
|
+
var and = (p1, p2) => (...args) => p1(...args) && p2(...args);
|
|
186
|
+
var or = (p1, p2) => (...args) => p1(...args) || p2(...args);
|
|
187
|
+
var once = (f) => {
|
|
188
|
+
let called = false;
|
|
189
|
+
let result;
|
|
190
|
+
return () => {
|
|
191
|
+
if (!called) {
|
|
192
|
+
result = f();
|
|
193
|
+
called = true;
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
var defaultTo = (fallback) => (a) => a === null || a === void 0 ? fallback : a;
|
|
199
|
+
var tuple = (f) => (args) => f(...args);
|
|
200
|
+
var untuple = (f) => (...args) => f(args);
|
|
201
|
+
|
|
202
|
+
// src/Composition/juxt.ts
|
|
203
|
+
function juxt(fns) {
|
|
204
|
+
return (a) => fns.map((f) => f(a));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/Composition/memoize.ts
|
|
208
|
+
var memoize = (f, options) => {
|
|
209
|
+
const cache = /* @__PURE__ */ new Map();
|
|
210
|
+
const keyFn = options?.key ?? ((a) => a);
|
|
211
|
+
return (a) => {
|
|
212
|
+
const key = keyFn(a);
|
|
213
|
+
if (cache.has(key)) {
|
|
214
|
+
return cache.get(key);
|
|
215
|
+
}
|
|
216
|
+
const result = f(a);
|
|
217
|
+
cache.set(key, result);
|
|
218
|
+
return result;
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
var memoizeWeak = (f) => {
|
|
222
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
223
|
+
return (a) => {
|
|
224
|
+
if (cache.has(a)) {
|
|
225
|
+
return cache.get(a);
|
|
226
|
+
}
|
|
227
|
+
const result = f(a);
|
|
228
|
+
cache.set(a, result);
|
|
229
|
+
return result;
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/Composition/not.ts
|
|
234
|
+
var not = (predicate) => (...args) => !predicate(...args);
|
|
235
|
+
|
|
236
|
+
// src/Composition/on.ts
|
|
237
|
+
var on = (f, g) => (a, b) => f(g(a), g(b));
|
|
238
|
+
|
|
239
|
+
// src/Composition/pipe.ts
|
|
240
|
+
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
|
|
241
|
+
switch (arguments.length) {
|
|
242
|
+
case 1: {
|
|
243
|
+
return a;
|
|
244
|
+
}
|
|
245
|
+
case 2: {
|
|
246
|
+
return ab(a);
|
|
247
|
+
}
|
|
248
|
+
case 3: {
|
|
249
|
+
return bc(ab(a));
|
|
250
|
+
}
|
|
251
|
+
case 4: {
|
|
252
|
+
return cd(bc(ab(a)));
|
|
253
|
+
}
|
|
254
|
+
case 5: {
|
|
255
|
+
return de(cd(bc(ab(a))));
|
|
256
|
+
}
|
|
257
|
+
case 6: {
|
|
258
|
+
return ef(de(cd(bc(ab(a)))));
|
|
259
|
+
}
|
|
260
|
+
case 7: {
|
|
261
|
+
return fg(ef(de(cd(bc(ab(a))))));
|
|
262
|
+
}
|
|
263
|
+
case 8: {
|
|
264
|
+
return gh(fg(ef(de(cd(bc(ab(a)))))));
|
|
265
|
+
}
|
|
266
|
+
case 9: {
|
|
267
|
+
return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
|
|
268
|
+
}
|
|
269
|
+
case 10: {
|
|
270
|
+
return ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))));
|
|
271
|
+
}
|
|
272
|
+
case 11: {
|
|
273
|
+
return jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
var when2 = (predicate, onTrue) => (a) => predicate(a) ? onTrue(a) : a;
|
|
278
|
+
var unless2 = (predicate, onFalse) => (a) => predicate(a) ? a : onFalse(a);
|
|
279
|
+
var either2 = (predicate, onTrue, onFalse) => (a) => predicate(a) ? onTrue(a) : onFalse(a);
|
|
280
|
+
var struct2 = (fields) => (a) => {
|
|
281
|
+
const result = {};
|
|
282
|
+
for (const key of Object.keys(fields)) {
|
|
283
|
+
result[key] = fields[key](a);
|
|
284
|
+
}
|
|
285
|
+
return result;
|
|
286
|
+
};
|
|
287
|
+
function safe2(a, ...fns) {
|
|
288
|
+
let result = a;
|
|
289
|
+
if (result === null || result === void 0) {
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
for (const fn of fns) {
|
|
293
|
+
result = fn(result);
|
|
294
|
+
if (result === null || result === void 0) {
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
async function async2(a, ...fns) {
|
|
301
|
+
let result = await a;
|
|
302
|
+
for (const fn of fns) {
|
|
303
|
+
result = await fn(result);
|
|
304
|
+
}
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
pipe.when = when2;
|
|
308
|
+
pipe.unless = unless2;
|
|
309
|
+
pipe.either = either2;
|
|
310
|
+
pipe.struct = struct2;
|
|
311
|
+
pipe.safe = safe2;
|
|
312
|
+
pipe.async = async2;
|
|
313
|
+
pipe.try = (f, onError) => (a) => {
|
|
314
|
+
try {
|
|
315
|
+
return f(a);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
return onError(error, a);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// src/Composition/tap.ts
|
|
322
|
+
import { inspect as nodeInspect } from "util";
|
|
323
|
+
|
|
324
|
+
// src/Types/Brand.ts
|
|
325
|
+
var Brand;
|
|
326
|
+
((Brand2) => {
|
|
327
|
+
Brand2.wrap = () => (value) => value;
|
|
328
|
+
Brand2.unwrap = (branded) => branded;
|
|
329
|
+
})(Brand || (Brand = {}));
|
|
330
|
+
|
|
331
|
+
// src/Types/RetryPolicy.ts
|
|
332
|
+
var RetryPolicy;
|
|
333
|
+
((RetryPolicy2) => {
|
|
334
|
+
RetryPolicy2.constant = (options) => ({
|
|
335
|
+
attempts: Math.max(1, options.attempts),
|
|
336
|
+
getDelay: () => options.delay
|
|
337
|
+
});
|
|
338
|
+
RetryPolicy2.exponential = (options) => {
|
|
339
|
+
const attempts = Math.max(1, options.attempts);
|
|
340
|
+
const initialMs = Duration.to.milliseconds(options.initial);
|
|
341
|
+
const factor = options.factor ?? 2;
|
|
342
|
+
const jitter = options.jitter ?? false;
|
|
343
|
+
return {
|
|
344
|
+
attempts,
|
|
345
|
+
getDelay: (attempt) => {
|
|
346
|
+
const rawMs = initialMs * factor ** Math.max(0, attempt - 1);
|
|
347
|
+
const finalMs = jitter ? Math.random() * rawMs : rawMs;
|
|
348
|
+
return Duration.milliseconds(finalMs);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
})(RetryPolicy || (RetryPolicy = {}));
|
|
353
|
+
|
|
354
|
+
// src/Types/Duration.ts
|
|
355
|
+
var Duration;
|
|
356
|
+
((Duration2) => {
|
|
357
|
+
const wrap = Brand.wrap();
|
|
358
|
+
Duration2.milliseconds = (ms) => wrap(ms);
|
|
359
|
+
Duration2.seconds = (s) => wrap(s * 1e3);
|
|
360
|
+
Duration2.minutes = (m) => wrap(m * 60 * 1e3);
|
|
361
|
+
Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
|
|
362
|
+
Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
|
|
363
|
+
let to;
|
|
364
|
+
((to2) => {
|
|
365
|
+
to2.milliseconds = (d) => Brand.unwrap(d);
|
|
366
|
+
to2.seconds = (d) => Brand.unwrap(d) / 1e3;
|
|
367
|
+
to2.minutes = (d) => Brand.unwrap(d) / (60 * 1e3);
|
|
368
|
+
to2.hours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
|
|
369
|
+
to2.days = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
|
|
370
|
+
})(to = Duration2.to || (Duration2.to = {}));
|
|
371
|
+
Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
|
|
372
|
+
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
373
|
+
})(Duration || (Duration = {}));
|
|
374
|
+
|
|
375
|
+
// src/Composition/tap.ts
|
|
376
|
+
function tap(f) {
|
|
377
|
+
return (a) => {
|
|
378
|
+
f(a);
|
|
379
|
+
return a;
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
((tap2) => {
|
|
383
|
+
tap2.log = (options) => (a) => {
|
|
384
|
+
const logger = options?.logger ?? console.log;
|
|
385
|
+
const formatter = options?.formatter ?? ((val) => {
|
|
386
|
+
try {
|
|
387
|
+
return typeof val === "object" && val !== null ? JSON.stringify(val) : String(val);
|
|
388
|
+
} catch {
|
|
389
|
+
return String(val);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
const formatted = formatter(a);
|
|
393
|
+
if (options?.label !== void 0) {
|
|
394
|
+
logger(`[${options.label}]: ${formatted}`);
|
|
395
|
+
} else {
|
|
396
|
+
logger(formatted);
|
|
397
|
+
}
|
|
398
|
+
return a;
|
|
399
|
+
};
|
|
400
|
+
tap2.inspect = (options) => (a) => {
|
|
401
|
+
const label = options?.label;
|
|
402
|
+
const depth = options?.depth ?? null;
|
|
403
|
+
const colors = options?.colors ?? true;
|
|
404
|
+
let formatted;
|
|
405
|
+
if (typeof nodeInspect === "function") {
|
|
406
|
+
formatted = nodeInspect(a, { depth, colors });
|
|
407
|
+
} else {
|
|
408
|
+
try {
|
|
409
|
+
formatted = JSON.stringify(a, null, 2);
|
|
410
|
+
} catch {
|
|
411
|
+
formatted = String(a);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (label !== void 0) {
|
|
415
|
+
console.log(`[${label}]: ${formatted}`);
|
|
416
|
+
} else {
|
|
417
|
+
console.log(formatted);
|
|
418
|
+
}
|
|
419
|
+
return a;
|
|
420
|
+
};
|
|
421
|
+
tap2.async = (fn, options) => (a) => {
|
|
422
|
+
const onError = options?.onError ?? console.error;
|
|
423
|
+
Promise.resolve(fn(a)).catch((err2) => {
|
|
424
|
+
onError(err2);
|
|
425
|
+
});
|
|
426
|
+
return a;
|
|
427
|
+
};
|
|
428
|
+
tap2.time = (fn, config) => (a) => {
|
|
429
|
+
const start = performance.now();
|
|
430
|
+
const triggerFinish = (duration) => {
|
|
431
|
+
if (config.label !== void 0) {
|
|
432
|
+
console.log(`[${config.label}]: ${Duration.to.milliseconds(duration)}ms`);
|
|
433
|
+
} else {
|
|
434
|
+
config.onFinish(duration);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
try {
|
|
438
|
+
const res = fn(a);
|
|
439
|
+
if (res !== null && (typeof res === "object" || typeof res === "function") && typeof res.then === "function") {
|
|
440
|
+
res.then(() => {
|
|
441
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
442
|
+
triggerFinish(duration);
|
|
443
|
+
}, () => {
|
|
444
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
445
|
+
triggerFinish(duration);
|
|
446
|
+
});
|
|
447
|
+
} else {
|
|
448
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
449
|
+
triggerFinish(duration);
|
|
450
|
+
}
|
|
451
|
+
} catch (err2) {
|
|
452
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
453
|
+
triggerFinish(duration);
|
|
454
|
+
throw err2;
|
|
455
|
+
}
|
|
456
|
+
return a;
|
|
457
|
+
};
|
|
458
|
+
})(tap || (tap = {}));
|
|
459
|
+
|
|
460
|
+
// src/Composition/uncurry.ts
|
|
461
|
+
function uncurry(f) {
|
|
462
|
+
return (...args) => {
|
|
463
|
+
const inner = f(...args.slice(0, f.length));
|
|
464
|
+
return inner.length === 0 ? inner() : inner(...args.slice(f.length));
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
var uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
|
|
468
|
+
var uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
|
|
469
|
+
|
|
470
|
+
// src/Core/Combinable.ts
|
|
471
|
+
var Combinable;
|
|
472
|
+
((Combinable2) => {
|
|
473
|
+
Combinable2.string = { empty: "", combine: (b) => (a) => a + b };
|
|
474
|
+
Combinable2.sum = { empty: 0, combine: (b) => (a) => a + b };
|
|
475
|
+
Combinable2.product = { empty: 1, combine: (b) => (a) => a * b };
|
|
476
|
+
Combinable2.all = { empty: true, combine: (b) => (a) => a && b };
|
|
477
|
+
Combinable2.any = { empty: false, combine: (b) => (a) => a || b };
|
|
478
|
+
Combinable2.array = () => ({ empty: [], combine: (b) => (a) => [...a, ...b] });
|
|
479
|
+
Combinable2.maybe = (inner) => ({
|
|
480
|
+
empty: Maybe.make.none(),
|
|
481
|
+
combine: (b) => (a) => Maybe.is.none(a) ? b : Maybe.is.none(b) ? a : Maybe.make.some(inner.combine(b.value)(a.value))
|
|
482
|
+
});
|
|
483
|
+
Combinable2.fold = (c) => (data) => data.reduce((acc, x) => c.combine(x)(acc), c.empty);
|
|
484
|
+
Combinable2.struct = (fields) => {
|
|
485
|
+
const empty = {};
|
|
486
|
+
for (const key in fields) {
|
|
487
|
+
if (Object.hasOwn(fields, key)) {
|
|
488
|
+
empty[key] = fields[key].empty;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
empty,
|
|
493
|
+
combine: (b) => (a) => {
|
|
494
|
+
const result = {};
|
|
495
|
+
for (const key in fields) {
|
|
496
|
+
if (Object.hasOwn(fields, key)) {
|
|
497
|
+
result[key] = fields[key].combine(b[key])(a[key]);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return result;
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
};
|
|
504
|
+
})(Combinable || (Combinable = {}));
|
|
505
|
+
|
|
506
|
+
// src/Core/Deferred.ts
|
|
507
|
+
var Deferred;
|
|
508
|
+
((Deferred2) => {
|
|
509
|
+
let from;
|
|
510
|
+
((from2) => {
|
|
511
|
+
from2.Promise = (p) => (
|
|
512
|
+
// eslint-disable-next-line unicorn/no-thenable -- Deferred is intentionally thenable; it is the mechanism that makes Task awaitable
|
|
513
|
+
{ then: ((f) => p.then(f)) }
|
|
514
|
+
);
|
|
515
|
+
})(from = Deferred2.from || (Deferred2.from = {}));
|
|
516
|
+
let to;
|
|
517
|
+
((to2) => {
|
|
518
|
+
to2.Promise = (d) => new globalThis.Promise((resolve) => d.then(resolve));
|
|
519
|
+
})(to = Deferred2.to || (Deferred2.to = {}));
|
|
520
|
+
Deferred2.all = (deferreds) => from.Promise(globalThis.Promise.all(deferreds.map((d) => to.Promise(d))));
|
|
521
|
+
Deferred2.race = (deferreds) => from.Promise(globalThis.Promise.race(deferreds.map((d) => to.Promise(d))));
|
|
522
|
+
})(Deferred || (Deferred = {}));
|
|
523
|
+
|
|
524
|
+
// src/Core/Equality.ts
|
|
525
|
+
var Equality;
|
|
526
|
+
((Equality3) => {
|
|
527
|
+
Equality3.string = (a, b) => a === b;
|
|
528
|
+
Equality3.number = (a, b) => a === b;
|
|
529
|
+
Equality3.boolean = (a, b) => a === b;
|
|
530
|
+
Equality3.date = (a, b) => a.getTime() === b.getTime();
|
|
531
|
+
Equality3.array = (eq) => (a, b) => a.length === b.length && a.every((x, i) => eq(x, b[i]));
|
|
532
|
+
Equality3.by = (f) => (eq) => (a, b) => eq(f(a), f(b));
|
|
533
|
+
Equality3.and = (eq2) => (eq1) => (a, b) => eq1(a, b) && eq2(a, b);
|
|
534
|
+
Equality3.struct = (fields) => (a, b) => {
|
|
535
|
+
for (const key in fields) {
|
|
536
|
+
if (Object.hasOwn(fields, key)) {
|
|
537
|
+
if (!fields[key](a[key], b[key])) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return true;
|
|
543
|
+
};
|
|
544
|
+
Equality3.tuple = (...equalities) => (a, b) => {
|
|
545
|
+
if (a.length !== b.length) {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
for (let i = 0; i < equalities.length; i++) {
|
|
549
|
+
if (!equalities[i](a[i], b[i])) {
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return true;
|
|
554
|
+
};
|
|
555
|
+
})(Equality || (Equality = {}));
|
|
556
|
+
|
|
557
|
+
// src/Core/Lazy.ts
|
|
558
|
+
var Lazy;
|
|
559
|
+
((Lazy2) => {
|
|
560
|
+
Lazy2.from = (f) => {
|
|
561
|
+
let done = false;
|
|
562
|
+
let cache;
|
|
563
|
+
return {
|
|
564
|
+
get: () => {
|
|
565
|
+
if (!done) {
|
|
566
|
+
cache = f();
|
|
567
|
+
done = true;
|
|
568
|
+
}
|
|
569
|
+
return cache;
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
};
|
|
573
|
+
Lazy2.evaluate = (lazy) => lazy.get();
|
|
574
|
+
Lazy2.map = (f) => (lazy) => Lazy2.from(() => f(lazy.get()));
|
|
575
|
+
Lazy2.chain = (f) => (lazy) => Lazy2.from(() => f(lazy.get()).get());
|
|
576
|
+
Lazy2.tap = (f) => (lazy) => Lazy2.from(() => {
|
|
577
|
+
const v = lazy.get();
|
|
578
|
+
f(v);
|
|
579
|
+
return v;
|
|
580
|
+
});
|
|
581
|
+
})(Lazy || (Lazy = {}));
|
|
582
|
+
|
|
583
|
+
// src/Core/Lens.ts
|
|
584
|
+
var Lens;
|
|
585
|
+
((Lens3) => {
|
|
586
|
+
let from;
|
|
587
|
+
((from2) => {
|
|
588
|
+
from2.accessors = (get2, set2) => ({ get: get2, set: set2 });
|
|
589
|
+
from2.property = () => (key) => (0, from2.accessors)((s) => s[key], (a) => (s) => ({ ...s, [key]: a }));
|
|
590
|
+
})(from = Lens3.from || (Lens3.from = {}));
|
|
591
|
+
Lens3.get = (lens) => (s) => lens.get(s);
|
|
592
|
+
Lens3.set = (lens) => (a) => (s) => lens.set(a)(s);
|
|
593
|
+
Lens3.modify = (lens) => (f) => (s) => lens.set(f(lens.get(s)))(s);
|
|
594
|
+
Lens3.andThen = (inner) => (outer) => from.accessors((s) => inner.get(outer.get(s)), (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s));
|
|
595
|
+
Lens3.andThenOptional = (inner) => (outer) => ({
|
|
596
|
+
get: (s) => inner.get(outer.get(s)),
|
|
597
|
+
set: (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
|
|
598
|
+
});
|
|
599
|
+
Lens3.toOptional = (lens) => ({
|
|
600
|
+
get: (s) => ({ kind: "Some", value: lens.get(s) }),
|
|
601
|
+
set: lens.set
|
|
602
|
+
});
|
|
603
|
+
})(Lens || (Lens = {}));
|
|
604
|
+
|
|
605
|
+
// src/Core/Logged.ts
|
|
606
|
+
var Logged;
|
|
607
|
+
((Logged2) => {
|
|
608
|
+
let from;
|
|
609
|
+
((from2) => {
|
|
610
|
+
from2.value = (val) => ({ value: val, log: [] });
|
|
611
|
+
from2.entry = (logEntry) => ({ value: void 0, log: [logEntry] });
|
|
612
|
+
})(from = Logged2.from || (Logged2.from = {}));
|
|
613
|
+
Logged2.map = (f) => (data) => ({
|
|
614
|
+
value: f(data.value),
|
|
615
|
+
log: data.log
|
|
616
|
+
});
|
|
617
|
+
Logged2.chain = (f) => (data) => {
|
|
618
|
+
const next = f(data.value);
|
|
619
|
+
return { value: next.value, log: [...data.log, ...next.log] };
|
|
620
|
+
};
|
|
621
|
+
Logged2.ap = (arg) => (data) => ({
|
|
622
|
+
value: data.value(arg.value),
|
|
623
|
+
log: [...data.log, ...arg.log]
|
|
624
|
+
});
|
|
625
|
+
Logged2.tap = (f) => (data) => {
|
|
626
|
+
f(data.value);
|
|
627
|
+
return data;
|
|
628
|
+
};
|
|
629
|
+
Logged2.run = (data) => [data.value, data.log];
|
|
630
|
+
Logged2.bindTo = (key) => (data) => (0, Logged2.map)((a) => ({ [key]: a }))(data);
|
|
631
|
+
Logged2.bind = (key, f) => (data) => (0, Logged2.chain)(
|
|
632
|
+
(a) => (0, Logged2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
633
|
+
)(data);
|
|
634
|
+
Logged2.focus = (lens) => (f) => (data) => ({
|
|
635
|
+
value: lens.set(f(lens.get(data.value)))(data.value),
|
|
636
|
+
log: data.log
|
|
637
|
+
});
|
|
638
|
+
})(Logged || (Logged = {}));
|
|
639
|
+
|
|
640
|
+
// src/Core/Maybe.ts
|
|
641
|
+
var _none = { kind: "None" };
|
|
642
|
+
var Maybe;
|
|
643
|
+
((Maybe3) => {
|
|
644
|
+
let make;
|
|
645
|
+
((make2) => {
|
|
646
|
+
make2.some = (value) => ({ kind: "Some", value });
|
|
647
|
+
make2.none = () => _none;
|
|
648
|
+
})(make = Maybe3.make || (Maybe3.make = {}));
|
|
649
|
+
let is;
|
|
650
|
+
((is2) => {
|
|
651
|
+
is2.some = (data) => data.kind === "Some";
|
|
652
|
+
is2.none = (data) => data.kind === "None";
|
|
653
|
+
})(is = Maybe3.is || (Maybe3.is = {}));
|
|
654
|
+
let to;
|
|
655
|
+
((to2) => {
|
|
656
|
+
to2.nullable = (data) => is.some(data) ? data.value : null;
|
|
657
|
+
to2.undefined = (data) => is.some(data) ? data.value : globalThis.undefined;
|
|
658
|
+
to2.Result = (onNone) => (data) => is.some(data) ? Result.make.ok(data.value) : Result.make.err(onNone());
|
|
659
|
+
})(to = Maybe3.to || (Maybe3.to = {}));
|
|
660
|
+
let from;
|
|
661
|
+
((from2) => {
|
|
662
|
+
from2.nullable = (value) => value === null || value === void 0 ? make.none() : make.some(value);
|
|
663
|
+
from2.Predicate = (pred) => (a) => pred(a) ? make.some(a) : make.none();
|
|
664
|
+
from2.Result = (data) => Result.is.ok(data) ? make.some(data.value) : make.none();
|
|
665
|
+
})(from = Maybe3.from || (Maybe3.from = {}));
|
|
666
|
+
Maybe3.map = (f) => (data) => is.some(data) ? make.some(f(data.value)) : data;
|
|
667
|
+
Maybe3.chain = (f) => (data) => is.some(data) ? f(data.value) : data;
|
|
668
|
+
Maybe3.fold = (onNone, onSome) => (data) => is.some(data) ? onSome(data.value) : onNone();
|
|
669
|
+
Maybe3.match = (cases) => (data) => is.some(data) ? cases.some(data.value) : cases.none();
|
|
670
|
+
Maybe3.getOrElse = (defaultValue) => (data) => is.some(data) ? data.value : defaultValue();
|
|
671
|
+
Maybe3.tap = (f) => (data) => {
|
|
672
|
+
if (is.some(data)) {
|
|
673
|
+
f(data.value);
|
|
674
|
+
}
|
|
675
|
+
return data;
|
|
676
|
+
};
|
|
677
|
+
Maybe3.filter = (predicate) => (data) => is.some(data) ? predicate(data.value) ? data : make.none() : data;
|
|
678
|
+
Maybe3.recover = (fallback) => (data) => is.some(data) ? data : fallback();
|
|
679
|
+
Maybe3.ap = (arg) => (data) => is.some(data) && is.some(arg) ? make.some(data.value(arg.value)) : make.none();
|
|
680
|
+
Maybe3.bindTo = (key) => (data) => (0, Maybe3.map)((a) => ({ [key]: a }))(data);
|
|
681
|
+
Maybe3.bind = (key, f) => (data) => (0, Maybe3.chain)(
|
|
682
|
+
(a) => (0, Maybe3.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
683
|
+
)(data);
|
|
684
|
+
Maybe3.struct = (fields) => {
|
|
685
|
+
const result = {};
|
|
686
|
+
for (const key in fields) {
|
|
687
|
+
if (Object.hasOwn(fields, key)) {
|
|
688
|
+
const res = fields[key];
|
|
689
|
+
if (is.none(res)) {
|
|
690
|
+
return res;
|
|
691
|
+
}
|
|
692
|
+
result[key] = res.value;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return make.some(result);
|
|
696
|
+
};
|
|
697
|
+
Maybe3.transposeResult = (data) => is.none(data) ? Result.make.ok(make.none()) : Result.is.ok(data.value) ? Result.make.ok(make.some(data.value.value)) : Result.make.err(data.value.error);
|
|
698
|
+
})(Maybe || (Maybe = {}));
|
|
699
|
+
|
|
700
|
+
// src/internal/Op.util.ts
|
|
701
|
+
var _abortedNil = { kind: "OpNil", reason: "aborted" };
|
|
702
|
+
var _droppedNil = { kind: "OpNil", reason: "dropped" };
|
|
703
|
+
var _replacedNil = { kind: "OpNil", reason: "replaced" };
|
|
704
|
+
var _evictedNil = { kind: "OpNil", reason: "evicted" };
|
|
705
|
+
var _idle = { kind: "Idle" };
|
|
706
|
+
var _pending = { kind: "Pending" };
|
|
707
|
+
var ok = (value) => ({ kind: "OpOk", value });
|
|
708
|
+
var err = (error) => ({ kind: "OpErr", error });
|
|
709
|
+
var getMs = (duration) => Duration.to.milliseconds(duration);
|
|
710
|
+
var cancellableWait = (duration, signal) => {
|
|
711
|
+
const rawMs = getMs(duration);
|
|
712
|
+
if (rawMs <= 0) {
|
|
713
|
+
return Promise.resolve();
|
|
714
|
+
}
|
|
715
|
+
return new Promise((resolve) => {
|
|
716
|
+
const id = setTimeout(resolve, rawMs);
|
|
717
|
+
signal.addEventListener("abort", () => {
|
|
718
|
+
clearTimeout(id);
|
|
719
|
+
resolve();
|
|
720
|
+
}, { once: true });
|
|
721
|
+
});
|
|
722
|
+
};
|
|
723
|
+
var runWithRetry = (op, input, signal, options, onRetrying) => {
|
|
724
|
+
const { attempts, backoff, when: shouldRetry } = options;
|
|
725
|
+
const getDelay = (n) => {
|
|
726
|
+
if (backoff === void 0) {
|
|
727
|
+
return void 0;
|
|
728
|
+
}
|
|
729
|
+
return typeof backoff === "function" ? backoff(n) : backoff;
|
|
730
|
+
};
|
|
731
|
+
const attempt = async (left) => {
|
|
732
|
+
const result = await Deferred.to.Promise(op._factory(input, signal));
|
|
733
|
+
if (result === null || signal.aborted) {
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
if (result.kind === "Ok") {
|
|
737
|
+
return result;
|
|
738
|
+
}
|
|
739
|
+
if (left <= 1) {
|
|
740
|
+
return result;
|
|
741
|
+
}
|
|
742
|
+
if (shouldRetry !== void 0 && !shouldRetry(result.error)) {
|
|
743
|
+
return result;
|
|
744
|
+
}
|
|
745
|
+
const attemptNumber = attempts - left + 1;
|
|
746
|
+
const delayDuration = getDelay(attemptNumber);
|
|
747
|
+
const ms = delayDuration ? getMs(delayDuration) : 0;
|
|
748
|
+
onRetrying({
|
|
749
|
+
kind: "Retrying",
|
|
750
|
+
attempt: attemptNumber,
|
|
751
|
+
lastError: result.error,
|
|
752
|
+
...ms > 0 ? { nextRetryIn: ms } : {}
|
|
753
|
+
});
|
|
754
|
+
if (delayDuration) {
|
|
755
|
+
await cancellableWait(delayDuration, signal);
|
|
756
|
+
}
|
|
757
|
+
if (signal.aborted) {
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
return attempt(left - 1);
|
|
761
|
+
};
|
|
762
|
+
return attempt(attempts);
|
|
763
|
+
};
|
|
764
|
+
var execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying) => {
|
|
765
|
+
const { signal } = controller;
|
|
766
|
+
const toOutcome = (r) => r === null ? _abortedNil : r.kind === "Ok" ? ok(r.value) : err(r.error);
|
|
767
|
+
const runPromise = retryOptions !== void 0 && onRetrying !== void 0 ? runWithRetry(op, input, signal, retryOptions, onRetrying).then(toOutcome) : Deferred.to.Promise(op._factory(input, signal)).then(toOutcome);
|
|
768
|
+
if (timeoutOptions === void 0) {
|
|
769
|
+
return Deferred.from.Promise(runPromise);
|
|
770
|
+
}
|
|
771
|
+
let timerId;
|
|
772
|
+
return Deferred.from.Promise(Promise.race([
|
|
773
|
+
runPromise.then((outcome) => {
|
|
774
|
+
clearTimeout(timerId);
|
|
775
|
+
return outcome;
|
|
776
|
+
}),
|
|
777
|
+
new Promise((resolve) => {
|
|
778
|
+
timerId = setTimeout(() => {
|
|
779
|
+
controller.abort();
|
|
780
|
+
resolve(err(timeoutOptions.onTimeout()));
|
|
781
|
+
}, getMs(timeoutOptions.duration));
|
|
782
|
+
})
|
|
783
|
+
]));
|
|
784
|
+
};
|
|
785
|
+
var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
786
|
+
let currentState = _idle;
|
|
787
|
+
let currentController;
|
|
788
|
+
let currentResolve;
|
|
789
|
+
let waitController;
|
|
790
|
+
let lastStartTime = 0;
|
|
791
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
792
|
+
const emit = (state) => {
|
|
793
|
+
currentState = state;
|
|
794
|
+
subscribers.forEach((cb) => cb(state));
|
|
795
|
+
};
|
|
796
|
+
const run = (input) => Deferred.from.Promise(
|
|
797
|
+
new Promise((resolve) => {
|
|
798
|
+
waitController?.abort();
|
|
799
|
+
waitController = void 0;
|
|
800
|
+
currentController?.abort();
|
|
801
|
+
const prev = currentResolve;
|
|
802
|
+
currentResolve = resolve;
|
|
803
|
+
currentController = new AbortController();
|
|
804
|
+
const controller = currentController;
|
|
805
|
+
prev?.(_replacedNil);
|
|
806
|
+
const startExecution = () => {
|
|
807
|
+
if (currentController !== controller) {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
lastStartTime = Date.now();
|
|
811
|
+
emit(_pending);
|
|
812
|
+
const onRetrying = retryOptions ? (r) => {
|
|
813
|
+
if (currentController === controller) {
|
|
814
|
+
emit(r);
|
|
815
|
+
}
|
|
816
|
+
} : void 0;
|
|
817
|
+
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
818
|
+
if (currentController !== controller) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
const r = currentResolve;
|
|
822
|
+
currentResolve = void 0;
|
|
823
|
+
currentController = void 0;
|
|
824
|
+
emit(outcome);
|
|
825
|
+
r?.(outcome);
|
|
826
|
+
});
|
|
827
|
+
};
|
|
828
|
+
const gap = minInterval !== void 0 ? Math.max(0, getMs(minInterval) - (Date.now() - lastStartTime)) : 0;
|
|
829
|
+
if (gap > 0) {
|
|
830
|
+
waitController = new AbortController();
|
|
831
|
+
const wc = waitController;
|
|
832
|
+
cancellableWait(Duration.milliseconds(gap), wc.signal).then(() => {
|
|
833
|
+
if (waitController === wc) {
|
|
834
|
+
waitController = void 0;
|
|
835
|
+
}
|
|
836
|
+
startExecution();
|
|
837
|
+
});
|
|
838
|
+
} else {
|
|
839
|
+
startExecution();
|
|
840
|
+
}
|
|
841
|
+
})
|
|
842
|
+
);
|
|
843
|
+
const abort = () => {
|
|
844
|
+
waitController?.abort();
|
|
845
|
+
waitController = void 0;
|
|
846
|
+
currentController?.abort();
|
|
847
|
+
currentController = void 0;
|
|
848
|
+
const r = currentResolve;
|
|
849
|
+
currentResolve = void 0;
|
|
850
|
+
if (currentState.kind !== "Idle") {
|
|
851
|
+
emit(_abortedNil);
|
|
852
|
+
}
|
|
853
|
+
r?.(_abortedNil);
|
|
854
|
+
};
|
|
855
|
+
return {
|
|
856
|
+
get state() {
|
|
857
|
+
return currentState;
|
|
858
|
+
},
|
|
859
|
+
run,
|
|
860
|
+
abort,
|
|
861
|
+
subscribe: (cb) => {
|
|
862
|
+
subscribers.add(cb);
|
|
863
|
+
if (currentState.kind !== "Idle") {
|
|
864
|
+
cb(currentState);
|
|
865
|
+
}
|
|
866
|
+
return () => subscribers.delete(cb);
|
|
867
|
+
},
|
|
868
|
+
reset: () => emit(_idle),
|
|
869
|
+
poll: (input, { interval }) => {
|
|
870
|
+
void run(input);
|
|
871
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
872
|
+
return () => clearInterval(id);
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
};
|
|
876
|
+
var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
|
|
877
|
+
let currentState = _idle;
|
|
878
|
+
let currentController;
|
|
879
|
+
let currentResolve;
|
|
880
|
+
let cooldownTimer;
|
|
881
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
882
|
+
const emit = (state) => {
|
|
883
|
+
currentState = state;
|
|
884
|
+
subscribers.forEach((cb) => cb(state));
|
|
885
|
+
};
|
|
886
|
+
const run = (input) => {
|
|
887
|
+
if (currentController !== void 0 || cooldownTimer !== void 0) {
|
|
888
|
+
return Deferred.from.Promise(Promise.resolve(_droppedNil));
|
|
889
|
+
}
|
|
890
|
+
return Deferred.from.Promise(
|
|
891
|
+
new Promise((resolve) => {
|
|
892
|
+
currentResolve = resolve;
|
|
893
|
+
currentController = new AbortController();
|
|
894
|
+
const controller = currentController;
|
|
895
|
+
emit(_pending);
|
|
896
|
+
const onRetrying = retryOptions ? (r) => {
|
|
897
|
+
if (currentController === controller) {
|
|
898
|
+
emit(r);
|
|
899
|
+
}
|
|
900
|
+
} : void 0;
|
|
901
|
+
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
902
|
+
if (currentController !== controller) {
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
const r = currentResolve;
|
|
906
|
+
currentResolve = void 0;
|
|
907
|
+
currentController = void 0;
|
|
908
|
+
emit(outcome);
|
|
909
|
+
r?.(outcome);
|
|
910
|
+
if (cooldown !== void 0) {
|
|
911
|
+
const rawCooldown = getMs(cooldown);
|
|
912
|
+
if (rawCooldown > 0) {
|
|
913
|
+
cooldownTimer = setTimeout(() => {
|
|
914
|
+
cooldownTimer = void 0;
|
|
915
|
+
}, rawCooldown);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
})
|
|
920
|
+
);
|
|
921
|
+
};
|
|
922
|
+
const abort = () => {
|
|
923
|
+
if (cooldownTimer !== void 0) {
|
|
924
|
+
clearTimeout(cooldownTimer);
|
|
925
|
+
cooldownTimer = void 0;
|
|
926
|
+
}
|
|
927
|
+
currentController?.abort();
|
|
928
|
+
currentController = void 0;
|
|
929
|
+
const r = currentResolve;
|
|
930
|
+
currentResolve = void 0;
|
|
931
|
+
if (currentState.kind !== "Idle") {
|
|
932
|
+
emit(_abortedNil);
|
|
933
|
+
}
|
|
934
|
+
r?.(_abortedNil);
|
|
935
|
+
};
|
|
936
|
+
return {
|
|
937
|
+
get state() {
|
|
938
|
+
return currentState;
|
|
939
|
+
},
|
|
940
|
+
run,
|
|
941
|
+
abort,
|
|
942
|
+
subscribe: (cb) => {
|
|
943
|
+
subscribers.add(cb);
|
|
944
|
+
if (currentState.kind !== "Idle") {
|
|
945
|
+
cb(currentState);
|
|
946
|
+
}
|
|
947
|
+
return () => subscribers.delete(cb);
|
|
948
|
+
},
|
|
949
|
+
reset: () => emit(_idle),
|
|
950
|
+
poll: (input, { interval }) => {
|
|
951
|
+
void run(input);
|
|
952
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
953
|
+
return () => clearInterval(id);
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
};
|
|
957
|
+
var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeoutOptions) => {
|
|
958
|
+
const maxConcurrency = concurrency ?? 1;
|
|
959
|
+
let currentState = _idle;
|
|
960
|
+
let generation = 0;
|
|
961
|
+
let inFlight = 0;
|
|
962
|
+
const queue = [];
|
|
963
|
+
const inflightControllers = /* @__PURE__ */ new Set();
|
|
964
|
+
const inflightResolvers = [];
|
|
965
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
966
|
+
const emit = (state) => {
|
|
967
|
+
currentState = state;
|
|
968
|
+
subscribers.forEach((cb) => cb(state));
|
|
969
|
+
};
|
|
970
|
+
const startOne = (input, resolve, myGeneration) => {
|
|
971
|
+
inFlight++;
|
|
972
|
+
const controller = new AbortController();
|
|
973
|
+
inflightControllers.add(controller);
|
|
974
|
+
inflightResolvers.push(resolve);
|
|
975
|
+
emit(_pending);
|
|
976
|
+
const onRetrying = retryOptions ? (r) => {
|
|
977
|
+
if (generation === myGeneration && inflightControllers.has(controller)) {
|
|
978
|
+
emit(r);
|
|
979
|
+
}
|
|
980
|
+
} : void 0;
|
|
981
|
+
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
982
|
+
inflightControllers.delete(controller);
|
|
983
|
+
const idx = inflightResolvers.indexOf(resolve);
|
|
984
|
+
if (idx !== -1) {
|
|
985
|
+
inflightResolvers.splice(idx, 1);
|
|
986
|
+
}
|
|
987
|
+
if (generation !== myGeneration) {
|
|
988
|
+
resolve(_abortedNil);
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
inFlight--;
|
|
992
|
+
emit(outcome);
|
|
993
|
+
resolve(outcome);
|
|
994
|
+
if (queue.length > 0) {
|
|
995
|
+
const next = queue.shift();
|
|
996
|
+
startOne(next.input, next.resolve, generation);
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
};
|
|
1000
|
+
const run = (input) => {
|
|
1001
|
+
const myGeneration = generation;
|
|
1002
|
+
if (dedupe !== void 0) {
|
|
1003
|
+
const idx = queue.findIndex((item) => dedupe(input, item.input));
|
|
1004
|
+
if (idx !== -1) {
|
|
1005
|
+
const dup = queue.splice(idx, 1)[0];
|
|
1006
|
+
dup.resolve(_droppedNil);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
if (inFlight < maxConcurrency) {
|
|
1010
|
+
return Deferred.from.Promise(
|
|
1011
|
+
new Promise((resolve) => {
|
|
1012
|
+
startOne(input, resolve, myGeneration);
|
|
1013
|
+
})
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
if (maxSize === void 0 || queue.length < maxSize) {
|
|
1017
|
+
return Deferred.from.Promise(
|
|
1018
|
+
new Promise((resolve) => {
|
|
1019
|
+
queue.push({ input, resolve });
|
|
1020
|
+
emit({ kind: "Queued", position: queue.length - 1 });
|
|
1021
|
+
})
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
if (overflow === "replace-last") {
|
|
1025
|
+
return Deferred.from.Promise(
|
|
1026
|
+
new Promise((resolve) => {
|
|
1027
|
+
const tail = queue.pop();
|
|
1028
|
+
tail.resolve(_evictedNil);
|
|
1029
|
+
queue.push({ input, resolve });
|
|
1030
|
+
emit({ kind: "Queued", position: queue.length - 1 });
|
|
1031
|
+
})
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
return Deferred.from.Promise(Promise.resolve(_droppedNil));
|
|
1035
|
+
};
|
|
1036
|
+
const abort = () => {
|
|
1037
|
+
generation++;
|
|
1038
|
+
inflightControllers.forEach((c) => c.abort());
|
|
1039
|
+
inflightControllers.clear();
|
|
1040
|
+
const toResolve = inflightResolvers.splice(0);
|
|
1041
|
+
const queuedResolvers = queue.splice(0).map((item) => item.resolve);
|
|
1042
|
+
inFlight = 0;
|
|
1043
|
+
if (currentState.kind !== "Idle") {
|
|
1044
|
+
emit(_abortedNil);
|
|
1045
|
+
}
|
|
1046
|
+
toResolve.forEach((r) => r(_abortedNil));
|
|
1047
|
+
queuedResolvers.forEach((r) => r(_abortedNil));
|
|
1048
|
+
};
|
|
1049
|
+
return {
|
|
1050
|
+
get state() {
|
|
1051
|
+
return currentState;
|
|
1052
|
+
},
|
|
1053
|
+
run,
|
|
1054
|
+
abort,
|
|
1055
|
+
subscribe: (cb) => {
|
|
1056
|
+
subscribers.add(cb);
|
|
1057
|
+
if (currentState.kind !== "Idle") {
|
|
1058
|
+
cb(currentState);
|
|
1059
|
+
}
|
|
1060
|
+
return () => subscribers.delete(cb);
|
|
1061
|
+
},
|
|
1062
|
+
reset: () => emit(_idle),
|
|
1063
|
+
poll: (input, { interval }) => {
|
|
1064
|
+
void run(input);
|
|
1065
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
1066
|
+
return () => clearInterval(id);
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
};
|
|
1070
|
+
var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
|
|
1071
|
+
const bufferSize = size ?? 1;
|
|
1072
|
+
let currentState = _idle;
|
|
1073
|
+
let currentController;
|
|
1074
|
+
let currentResolve;
|
|
1075
|
+
const buffer = [];
|
|
1076
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
1077
|
+
const emit = (state) => {
|
|
1078
|
+
currentState = state;
|
|
1079
|
+
subscribers.forEach((cb) => cb(state));
|
|
1080
|
+
};
|
|
1081
|
+
const startRun = (input, resolve) => {
|
|
1082
|
+
currentResolve = resolve;
|
|
1083
|
+
currentController = new AbortController();
|
|
1084
|
+
const controller = currentController;
|
|
1085
|
+
emit(_pending);
|
|
1086
|
+
const onRetrying = retryOptions ? (r) => {
|
|
1087
|
+
if (currentController === controller) {
|
|
1088
|
+
emit(r);
|
|
1089
|
+
}
|
|
1090
|
+
} : void 0;
|
|
1091
|
+
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
1092
|
+
if (currentController !== controller) {
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
const r = currentResolve;
|
|
1096
|
+
currentResolve = void 0;
|
|
1097
|
+
currentController = void 0;
|
|
1098
|
+
emit(outcome);
|
|
1099
|
+
r?.(outcome);
|
|
1100
|
+
if (buffer.length > 0) {
|
|
1101
|
+
const next = buffer.shift();
|
|
1102
|
+
startRun(next.input, next.resolve);
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
};
|
|
1106
|
+
const run = (input) => Deferred.from.Promise(
|
|
1107
|
+
new Promise((resolve) => {
|
|
1108
|
+
if (currentController === void 0) {
|
|
1109
|
+
startRun(input, resolve);
|
|
1110
|
+
} else if (buffer.length < bufferSize) {
|
|
1111
|
+
buffer.push({ input, resolve });
|
|
1112
|
+
emit({ kind: "Queued", position: buffer.length - 1 });
|
|
1113
|
+
} else {
|
|
1114
|
+
const evicted = buffer.shift();
|
|
1115
|
+
evicted.resolve(_evictedNil);
|
|
1116
|
+
buffer.push({ input, resolve });
|
|
1117
|
+
emit({ kind: "Queued", position: buffer.length - 1 });
|
|
1118
|
+
}
|
|
1119
|
+
})
|
|
1120
|
+
);
|
|
1121
|
+
const abort = () => {
|
|
1122
|
+
currentController?.abort();
|
|
1123
|
+
currentController = void 0;
|
|
1124
|
+
const cr = currentResolve;
|
|
1125
|
+
currentResolve = void 0;
|
|
1126
|
+
const bufferedResolvers = buffer.splice(0).map((item) => item.resolve);
|
|
1127
|
+
if (currentState.kind !== "Idle") {
|
|
1128
|
+
emit(_abortedNil);
|
|
1129
|
+
}
|
|
1130
|
+
cr?.(_abortedNil);
|
|
1131
|
+
bufferedResolvers.forEach((r) => r(_abortedNil));
|
|
1132
|
+
};
|
|
1133
|
+
return {
|
|
1134
|
+
get state() {
|
|
1135
|
+
return currentState;
|
|
1136
|
+
},
|
|
1137
|
+
run,
|
|
1138
|
+
abort,
|
|
1139
|
+
subscribe: (cb) => {
|
|
1140
|
+
subscribers.add(cb);
|
|
1141
|
+
if (currentState.kind !== "Idle") {
|
|
1142
|
+
cb(currentState);
|
|
1143
|
+
}
|
|
1144
|
+
return () => subscribers.delete(cb);
|
|
1145
|
+
},
|
|
1146
|
+
reset: () => emit(_idle),
|
|
1147
|
+
poll: (input, { interval }) => {
|
|
1148
|
+
void run(input);
|
|
1149
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
1150
|
+
return () => clearInterval(id);
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
};
|
|
1154
|
+
var makeDebounced = (op, duration, leading, maxWait, retryOptions, timeoutOptions) => {
|
|
1155
|
+
let currentState = _idle;
|
|
1156
|
+
let currentController;
|
|
1157
|
+
let currentResolve;
|
|
1158
|
+
let leadingController;
|
|
1159
|
+
let leadingResolve;
|
|
1160
|
+
let pendingResolve;
|
|
1161
|
+
let timerId;
|
|
1162
|
+
let pendingInput;
|
|
1163
|
+
let firstCallAt = 0;
|
|
1164
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
1165
|
+
const emit = (state) => {
|
|
1166
|
+
currentState = state;
|
|
1167
|
+
subscribers.forEach((cb) => cb(state));
|
|
1168
|
+
};
|
|
1169
|
+
const fireLeading = (input, resolve) => {
|
|
1170
|
+
leadingController = new AbortController();
|
|
1171
|
+
const controller = leadingController;
|
|
1172
|
+
leadingResolve = resolve;
|
|
1173
|
+
emit(_pending);
|
|
1174
|
+
const onRetrying = retryOptions ? (r) => {
|
|
1175
|
+
if (leadingController === controller) {
|
|
1176
|
+
emit(r);
|
|
1177
|
+
}
|
|
1178
|
+
} : void 0;
|
|
1179
|
+
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
1180
|
+
if (leadingController !== controller) {
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
const r = leadingResolve;
|
|
1184
|
+
leadingResolve = void 0;
|
|
1185
|
+
leadingController = void 0;
|
|
1186
|
+
emit(outcome);
|
|
1187
|
+
r?.(outcome);
|
|
1188
|
+
});
|
|
1189
|
+
};
|
|
1190
|
+
const fireTrailing = () => {
|
|
1191
|
+
timerId = void 0;
|
|
1192
|
+
firstCallAt = 0;
|
|
1193
|
+
const capturedResolve = pendingResolve;
|
|
1194
|
+
pendingResolve = void 0;
|
|
1195
|
+
if (capturedResolve === void 0) {
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
currentResolve = capturedResolve;
|
|
1199
|
+
const toRun = pendingInput;
|
|
1200
|
+
pendingInput = void 0;
|
|
1201
|
+
currentController = new AbortController();
|
|
1202
|
+
const controller = currentController;
|
|
1203
|
+
emit(_pending);
|
|
1204
|
+
const onRetrying = retryOptions ? (r) => {
|
|
1205
|
+
if (currentController === controller) {
|
|
1206
|
+
emit(r);
|
|
1207
|
+
}
|
|
1208
|
+
} : void 0;
|
|
1209
|
+
execute(op, toRun, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
1210
|
+
if (currentController !== controller) {
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
const r = currentResolve;
|
|
1214
|
+
currentResolve = void 0;
|
|
1215
|
+
currentController = void 0;
|
|
1216
|
+
emit(outcome);
|
|
1217
|
+
r?.(outcome);
|
|
1218
|
+
});
|
|
1219
|
+
};
|
|
1220
|
+
const scheduleTrailing = () => {
|
|
1221
|
+
if (timerId !== void 0) {
|
|
1222
|
+
clearTimeout(timerId);
|
|
1223
|
+
}
|
|
1224
|
+
let delay = getMs(duration);
|
|
1225
|
+
if (maxWait !== void 0 && firstCallAt > 0) {
|
|
1226
|
+
const maxDelay = firstCallAt + getMs(maxWait) - Date.now();
|
|
1227
|
+
delay = Math.min(getMs(duration), Math.max(0, maxDelay));
|
|
1228
|
+
}
|
|
1229
|
+
timerId = setTimeout(fireTrailing, delay);
|
|
1230
|
+
};
|
|
1231
|
+
const inDebounceWindow = () => timerId !== void 0 || leadingController !== void 0 || currentController !== void 0;
|
|
1232
|
+
const run = (input) => Deferred.from.Promise(
|
|
1233
|
+
new Promise((resolve) => {
|
|
1234
|
+
if (!inDebounceWindow()) {
|
|
1235
|
+
firstCallAt = Date.now();
|
|
1236
|
+
if (leading) {
|
|
1237
|
+
fireLeading(input, resolve);
|
|
1238
|
+
scheduleTrailing();
|
|
1239
|
+
} else {
|
|
1240
|
+
pendingInput = input;
|
|
1241
|
+
pendingResolve = resolve;
|
|
1242
|
+
scheduleTrailing();
|
|
1243
|
+
}
|
|
1244
|
+
} else {
|
|
1245
|
+
const prev = pendingResolve;
|
|
1246
|
+
pendingInput = input;
|
|
1247
|
+
pendingResolve = resolve;
|
|
1248
|
+
prev?.(_evictedNil);
|
|
1249
|
+
scheduleTrailing();
|
|
1250
|
+
}
|
|
1251
|
+
})
|
|
1252
|
+
);
|
|
1253
|
+
const abort = () => {
|
|
1254
|
+
if (timerId !== void 0) {
|
|
1255
|
+
clearTimeout(timerId);
|
|
1256
|
+
timerId = void 0;
|
|
1257
|
+
pendingInput = void 0;
|
|
1258
|
+
firstCallAt = 0;
|
|
1259
|
+
}
|
|
1260
|
+
const pr = pendingResolve;
|
|
1261
|
+
pendingResolve = void 0;
|
|
1262
|
+
const cr = currentResolve;
|
|
1263
|
+
currentResolve = void 0;
|
|
1264
|
+
currentController?.abort();
|
|
1265
|
+
currentController = void 0;
|
|
1266
|
+
const lr = leadingResolve;
|
|
1267
|
+
leadingResolve = void 0;
|
|
1268
|
+
leadingController?.abort();
|
|
1269
|
+
leadingController = void 0;
|
|
1270
|
+
if (currentState.kind !== "Idle") {
|
|
1271
|
+
emit(_abortedNil);
|
|
1272
|
+
}
|
|
1273
|
+
pr?.(_abortedNil);
|
|
1274
|
+
cr?.(_abortedNil);
|
|
1275
|
+
lr?.(_abortedNil);
|
|
1276
|
+
};
|
|
1277
|
+
return {
|
|
1278
|
+
get state() {
|
|
1279
|
+
return currentState;
|
|
1280
|
+
},
|
|
1281
|
+
run,
|
|
1282
|
+
abort,
|
|
1283
|
+
subscribe: (cb) => {
|
|
1284
|
+
subscribers.add(cb);
|
|
1285
|
+
if (currentState.kind !== "Idle") {
|
|
1286
|
+
cb(currentState);
|
|
1287
|
+
}
|
|
1288
|
+
return () => subscribers.delete(cb);
|
|
1289
|
+
},
|
|
1290
|
+
reset: () => emit(_idle),
|
|
1291
|
+
poll: (input, { interval }) => {
|
|
1292
|
+
void run(input);
|
|
1293
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
1294
|
+
return () => clearInterval(id);
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
};
|
|
1298
|
+
var makeThrottled = (op, duration, trailing, retryOptions, timeoutOptions) => {
|
|
1299
|
+
let currentState = _idle;
|
|
1300
|
+
let currentController;
|
|
1301
|
+
let currentResolve;
|
|
1302
|
+
let cooldownTimer;
|
|
1303
|
+
let pendingInput;
|
|
1304
|
+
let pendingResolve;
|
|
1305
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
1306
|
+
const emit = (state) => {
|
|
1307
|
+
currentState = state;
|
|
1308
|
+
subscribers.forEach((cb) => cb(state));
|
|
1309
|
+
};
|
|
1310
|
+
const fireOp = (input, resolve) => {
|
|
1311
|
+
currentResolve = resolve;
|
|
1312
|
+
currentController = new AbortController();
|
|
1313
|
+
const controller = currentController;
|
|
1314
|
+
emit(_pending);
|
|
1315
|
+
const onRetrying = retryOptions ? (r) => {
|
|
1316
|
+
if (currentController === controller) {
|
|
1317
|
+
emit(r);
|
|
1318
|
+
}
|
|
1319
|
+
} : void 0;
|
|
1320
|
+
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
1321
|
+
if (currentController !== controller) {
|
|
1322
|
+
return;
|
|
1323
|
+
}
|
|
1324
|
+
const r = currentResolve;
|
|
1325
|
+
currentResolve = void 0;
|
|
1326
|
+
currentController = void 0;
|
|
1327
|
+
emit(outcome);
|
|
1328
|
+
r?.(outcome);
|
|
1329
|
+
});
|
|
1330
|
+
};
|
|
1331
|
+
const startCooldown = () => {
|
|
1332
|
+
cooldownTimer = setTimeout(() => {
|
|
1333
|
+
cooldownTimer = void 0;
|
|
1334
|
+
if (trailing && pendingInput !== void 0) {
|
|
1335
|
+
const input = pendingInput;
|
|
1336
|
+
const resolve = pendingResolve;
|
|
1337
|
+
pendingInput = void 0;
|
|
1338
|
+
pendingResolve = void 0;
|
|
1339
|
+
fireOp(input, resolve);
|
|
1340
|
+
startCooldown();
|
|
1341
|
+
}
|
|
1342
|
+
}, getMs(duration));
|
|
1343
|
+
};
|
|
1344
|
+
const run = (input) => {
|
|
1345
|
+
if (cooldownTimer !== void 0) {
|
|
1346
|
+
if (!trailing) {
|
|
1347
|
+
return Deferred.from.Promise(Promise.resolve(_droppedNil));
|
|
1348
|
+
}
|
|
1349
|
+
return Deferred.from.Promise(
|
|
1350
|
+
new Promise((resolve) => {
|
|
1351
|
+
const prev = pendingResolve;
|
|
1352
|
+
pendingInput = input;
|
|
1353
|
+
pendingResolve = resolve;
|
|
1354
|
+
prev?.(_evictedNil);
|
|
1355
|
+
})
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
return Deferred.from.Promise(
|
|
1359
|
+
new Promise((resolve) => {
|
|
1360
|
+
fireOp(input, resolve);
|
|
1361
|
+
startCooldown();
|
|
1362
|
+
})
|
|
1363
|
+
);
|
|
1364
|
+
};
|
|
1365
|
+
const abort = () => {
|
|
1366
|
+
if (cooldownTimer !== void 0) {
|
|
1367
|
+
clearTimeout(cooldownTimer);
|
|
1368
|
+
cooldownTimer = void 0;
|
|
1369
|
+
}
|
|
1370
|
+
currentController?.abort();
|
|
1371
|
+
currentController = void 0;
|
|
1372
|
+
const cr = currentResolve;
|
|
1373
|
+
currentResolve = void 0;
|
|
1374
|
+
const pr = pendingResolve;
|
|
1375
|
+
pendingResolve = void 0;
|
|
1376
|
+
pendingInput = void 0;
|
|
1377
|
+
if (currentState.kind !== "Idle") {
|
|
1378
|
+
emit(_abortedNil);
|
|
1379
|
+
}
|
|
1380
|
+
cr?.(_abortedNil);
|
|
1381
|
+
pr?.(_abortedNil);
|
|
1382
|
+
};
|
|
1383
|
+
return {
|
|
1384
|
+
get state() {
|
|
1385
|
+
return currentState;
|
|
1386
|
+
},
|
|
1387
|
+
run,
|
|
1388
|
+
abort,
|
|
1389
|
+
subscribe: (cb) => {
|
|
1390
|
+
subscribers.add(cb);
|
|
1391
|
+
if (currentState.kind !== "Idle") {
|
|
1392
|
+
cb(currentState);
|
|
1393
|
+
}
|
|
1394
|
+
return () => subscribers.delete(cb);
|
|
1395
|
+
},
|
|
1396
|
+
reset: () => emit(_idle),
|
|
1397
|
+
poll: (input, { interval }) => {
|
|
1398
|
+
void run(input);
|
|
1399
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
1400
|
+
return () => clearInterval(id);
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
};
|
|
1404
|
+
var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
|
|
1405
|
+
let currentState = _idle;
|
|
1406
|
+
let inflight = 0;
|
|
1407
|
+
let generation = 0;
|
|
1408
|
+
const controllers = /* @__PURE__ */ new Set();
|
|
1409
|
+
const inflightResolvers = [];
|
|
1410
|
+
const overflowQueue = [];
|
|
1411
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
1412
|
+
const emit = (state) => {
|
|
1413
|
+
currentState = state;
|
|
1414
|
+
subscribers.forEach((cb) => cb(state));
|
|
1415
|
+
};
|
|
1416
|
+
const startOne = (input, resolve, myGeneration) => {
|
|
1417
|
+
inflight++;
|
|
1418
|
+
const controller = new AbortController();
|
|
1419
|
+
controllers.add(controller);
|
|
1420
|
+
inflightResolvers.push(resolve);
|
|
1421
|
+
emit(_pending);
|
|
1422
|
+
const onRetrying = retryOptions ? (r) => {
|
|
1423
|
+
if (generation === myGeneration && controllers.has(controller)) {
|
|
1424
|
+
emit(r);
|
|
1425
|
+
}
|
|
1426
|
+
} : void 0;
|
|
1427
|
+
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
1428
|
+
controllers.delete(controller);
|
|
1429
|
+
const idx = inflightResolvers.indexOf(resolve);
|
|
1430
|
+
if (idx !== -1) {
|
|
1431
|
+
inflightResolvers.splice(idx, 1);
|
|
1432
|
+
}
|
|
1433
|
+
if (generation !== myGeneration) {
|
|
1434
|
+
resolve(_abortedNil);
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
inflight--;
|
|
1438
|
+
emit(outcome);
|
|
1439
|
+
resolve(outcome);
|
|
1440
|
+
if (overflowQueue.length > 0) {
|
|
1441
|
+
const next = overflowQueue.shift();
|
|
1442
|
+
startOne(next.input, next.resolve, generation);
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
};
|
|
1446
|
+
const run = (input) => {
|
|
1447
|
+
const myGeneration = generation;
|
|
1448
|
+
if (inflight < n) {
|
|
1449
|
+
return Deferred.from.Promise(
|
|
1450
|
+
new Promise((resolve) => {
|
|
1451
|
+
startOne(input, resolve, myGeneration);
|
|
1452
|
+
})
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
if (overflow === "drop") {
|
|
1456
|
+
return Deferred.from.Promise(Promise.resolve(_droppedNil));
|
|
1457
|
+
}
|
|
1458
|
+
return Deferred.from.Promise(
|
|
1459
|
+
new Promise((resolve) => {
|
|
1460
|
+
overflowQueue.push({ input, resolve });
|
|
1461
|
+
emit({ kind: "Queued", position: overflowQueue.length - 1 });
|
|
1462
|
+
})
|
|
1463
|
+
);
|
|
1464
|
+
};
|
|
1465
|
+
const abort = () => {
|
|
1466
|
+
generation++;
|
|
1467
|
+
controllers.forEach((c) => c.abort());
|
|
1468
|
+
controllers.clear();
|
|
1469
|
+
const toResolve = inflightResolvers.splice(0);
|
|
1470
|
+
const queuedResolvers = overflowQueue.splice(0).map((item) => item.resolve);
|
|
1471
|
+
inflight = 0;
|
|
1472
|
+
if (currentState.kind !== "Idle") {
|
|
1473
|
+
emit(_abortedNil);
|
|
1474
|
+
}
|
|
1475
|
+
toResolve.forEach((r) => r(_abortedNil));
|
|
1476
|
+
queuedResolvers.forEach((r) => r(_abortedNil));
|
|
1477
|
+
};
|
|
1478
|
+
return {
|
|
1479
|
+
get state() {
|
|
1480
|
+
return currentState;
|
|
1481
|
+
},
|
|
1482
|
+
run,
|
|
1483
|
+
abort,
|
|
1484
|
+
subscribe: (cb) => {
|
|
1485
|
+
subscribers.add(cb);
|
|
1486
|
+
if (currentState.kind !== "Idle") {
|
|
1487
|
+
cb(currentState);
|
|
1488
|
+
}
|
|
1489
|
+
return () => subscribers.delete(cb);
|
|
1490
|
+
},
|
|
1491
|
+
reset: () => emit(_idle),
|
|
1492
|
+
poll: (input, { interval }) => {
|
|
1493
|
+
void run(input);
|
|
1494
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
1495
|
+
return () => clearInterval(id);
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
};
|
|
1499
|
+
var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
1500
|
+
const stateMap = /* @__PURE__ */ new Map();
|
|
1501
|
+
const slots = /* @__PURE__ */ new Map();
|
|
1502
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
1503
|
+
const emitSnapshot = () => {
|
|
1504
|
+
const snapshot = new Map(stateMap);
|
|
1505
|
+
subscribers.forEach((cb) => cb(snapshot));
|
|
1506
|
+
};
|
|
1507
|
+
const run = (input) => {
|
|
1508
|
+
const k = keyFn(input);
|
|
1509
|
+
if (slots.has(k)) {
|
|
1510
|
+
if (perKey === "exclusive") {
|
|
1511
|
+
return Deferred.from.Promise(Promise.resolve(_droppedNil));
|
|
1512
|
+
}
|
|
1513
|
+
const existing = slots.get(k);
|
|
1514
|
+
existing.controller.abort();
|
|
1515
|
+
const prev = existing.resolve;
|
|
1516
|
+
slots.delete(k);
|
|
1517
|
+
prev(_replacedNil);
|
|
1518
|
+
}
|
|
1519
|
+
return Deferred.from.Promise(
|
|
1520
|
+
new Promise((resolve) => {
|
|
1521
|
+
const controller = new AbortController();
|
|
1522
|
+
slots.set(k, { controller, resolve });
|
|
1523
|
+
stateMap.set(k, _pending);
|
|
1524
|
+
emitSnapshot();
|
|
1525
|
+
execute(op, input, controller, void 0, timeoutOptions).then((outcome) => {
|
|
1526
|
+
const slot = slots.get(k);
|
|
1527
|
+
if (!slot || slot.controller !== controller) {
|
|
1528
|
+
resolve(_abortedNil);
|
|
1529
|
+
return;
|
|
1530
|
+
}
|
|
1531
|
+
slots.delete(k);
|
|
1532
|
+
stateMap.set(k, outcome);
|
|
1533
|
+
emitSnapshot();
|
|
1534
|
+
resolve(outcome);
|
|
1535
|
+
});
|
|
1536
|
+
})
|
|
1537
|
+
);
|
|
1538
|
+
};
|
|
1539
|
+
const abort = (key) => {
|
|
1540
|
+
if (key !== void 0) {
|
|
1541
|
+
const slot = slots.get(key);
|
|
1542
|
+
if (slot) {
|
|
1543
|
+
slot.controller.abort();
|
|
1544
|
+
const r = slot.resolve;
|
|
1545
|
+
slots.delete(key);
|
|
1546
|
+
stateMap.set(key, _abortedNil);
|
|
1547
|
+
emitSnapshot();
|
|
1548
|
+
r(_abortedNil);
|
|
1549
|
+
}
|
|
1550
|
+
} else {
|
|
1551
|
+
const toResolve = [];
|
|
1552
|
+
for (const [k, slot] of slots) {
|
|
1553
|
+
slot.controller.abort();
|
|
1554
|
+
toResolve.push(slot.resolve);
|
|
1555
|
+
stateMap.set(k, _abortedNil);
|
|
1556
|
+
}
|
|
1557
|
+
slots.clear();
|
|
1558
|
+
if (toResolve.length > 0) {
|
|
1559
|
+
emitSnapshot();
|
|
1560
|
+
}
|
|
1561
|
+
toResolve.forEach((r) => r(_abortedNil));
|
|
1562
|
+
}
|
|
1563
|
+
};
|
|
1564
|
+
return {
|
|
1565
|
+
get state() {
|
|
1566
|
+
return new Map(stateMap);
|
|
1567
|
+
},
|
|
1568
|
+
run,
|
|
1569
|
+
abort,
|
|
1570
|
+
subscribe: (cb) => {
|
|
1571
|
+
subscribers.add(cb);
|
|
1572
|
+
if (stateMap.size > 0) {
|
|
1573
|
+
cb(new Map(stateMap));
|
|
1574
|
+
}
|
|
1575
|
+
return () => subscribers.delete(cb);
|
|
1576
|
+
},
|
|
1577
|
+
reset: () => {
|
|
1578
|
+
stateMap.clear();
|
|
1579
|
+
emitSnapshot();
|
|
1580
|
+
},
|
|
1581
|
+
poll: (input, { interval }) => {
|
|
1582
|
+
void run(input);
|
|
1583
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
1584
|
+
return () => clearInterval(id);
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
};
|
|
1588
|
+
var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
1589
|
+
let currentState = _idle;
|
|
1590
|
+
let currentController;
|
|
1591
|
+
let currentResolve;
|
|
1592
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
1593
|
+
const emit = (state) => {
|
|
1594
|
+
currentState = state;
|
|
1595
|
+
subscribers.forEach((cb) => cb(state));
|
|
1596
|
+
};
|
|
1597
|
+
const run = (input) => {
|
|
1598
|
+
if (currentState.kind !== "Idle") {
|
|
1599
|
+
return Deferred.from.Promise(Promise.resolve(_droppedNil));
|
|
1600
|
+
}
|
|
1601
|
+
return Deferred.from.Promise(
|
|
1602
|
+
new Promise((resolve) => {
|
|
1603
|
+
currentResolve = resolve;
|
|
1604
|
+
currentController = new AbortController();
|
|
1605
|
+
const controller = currentController;
|
|
1606
|
+
emit(_pending);
|
|
1607
|
+
const onRetrying = retryOptions ? (r) => {
|
|
1608
|
+
if (currentController === controller) {
|
|
1609
|
+
emit(r);
|
|
1610
|
+
}
|
|
1611
|
+
} : void 0;
|
|
1612
|
+
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
1613
|
+
if (currentController !== controller) {
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
const r = currentResolve;
|
|
1617
|
+
currentResolve = void 0;
|
|
1618
|
+
currentController = void 0;
|
|
1619
|
+
emit(outcome);
|
|
1620
|
+
r?.(outcome);
|
|
1621
|
+
});
|
|
1622
|
+
})
|
|
1623
|
+
);
|
|
1624
|
+
};
|
|
1625
|
+
const abort = () => {
|
|
1626
|
+
currentController?.abort();
|
|
1627
|
+
currentController = void 0;
|
|
1628
|
+
const r = currentResolve;
|
|
1629
|
+
currentResolve = void 0;
|
|
1630
|
+
if (currentState.kind !== "Idle") {
|
|
1631
|
+
emit(_abortedNil);
|
|
1632
|
+
}
|
|
1633
|
+
r?.(_abortedNil);
|
|
1634
|
+
};
|
|
1635
|
+
return {
|
|
1636
|
+
get state() {
|
|
1637
|
+
return currentState;
|
|
1638
|
+
},
|
|
1639
|
+
run,
|
|
1640
|
+
abort,
|
|
1641
|
+
subscribe: (cb) => {
|
|
1642
|
+
subscribers.add(cb);
|
|
1643
|
+
if (currentState.kind !== "Idle") {
|
|
1644
|
+
cb(currentState);
|
|
1645
|
+
}
|
|
1646
|
+
return () => subscribers.delete(cb);
|
|
1647
|
+
},
|
|
1648
|
+
reset: () => emit(_idle),
|
|
1649
|
+
poll: (input, { interval }) => {
|
|
1650
|
+
void run(input);
|
|
1651
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
1652
|
+
return () => clearInterval(id);
|
|
1653
|
+
}
|
|
1654
|
+
};
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1657
|
+
// src/Core/Op.ts
|
|
1658
|
+
var Op;
|
|
1659
|
+
((Op2) => {
|
|
1660
|
+
Op2.nil = (reason) => ({ kind: "OpNil", reason });
|
|
1661
|
+
Op2.create = (factory, onError) => ({
|
|
1662
|
+
_factory: (input, signal) => Deferred.from.Promise(
|
|
1663
|
+
factory(signal)(input).then((value) => Result.make.ok(value)).catch((error) => signal.aborted ? null : Result.make.err(onError(error)))
|
|
1664
|
+
)
|
|
1665
|
+
});
|
|
1666
|
+
Op2.lift = (f) => (0, Op2.create)((signal) => (input) => f(input, signal), (e) => e);
|
|
1667
|
+
Op2.ok = (value) => ({ kind: "OpOk", value });
|
|
1668
|
+
Op2.err = (error) => ({ kind: "OpErr", error });
|
|
1669
|
+
Op2.isIdle = (state) => state.kind === "Idle";
|
|
1670
|
+
Op2.isPending = (state) => state.kind === "Pending";
|
|
1671
|
+
Op2.isQueued = (state) => state.kind === "Queued";
|
|
1672
|
+
Op2.isRetrying = (state) => state.kind === "Retrying";
|
|
1673
|
+
Op2.isOk = (state) => state.kind === "OpOk";
|
|
1674
|
+
Op2.isErr = (state) => state.kind === "OpErr";
|
|
1675
|
+
Op2.isNil = (state) => state.kind === "OpNil";
|
|
1676
|
+
Op2.match = (cases) => (outcome) => {
|
|
1677
|
+
if (outcome.kind === "OpOk") {
|
|
1678
|
+
return cases.ok(outcome.value);
|
|
1679
|
+
}
|
|
1680
|
+
if (outcome.kind === "OpErr") {
|
|
1681
|
+
return cases.err(outcome.error);
|
|
1682
|
+
}
|
|
1683
|
+
return cases.nil();
|
|
1684
|
+
};
|
|
1685
|
+
Op2.fold = (onErr, onNil, onOk) => (outcome) => {
|
|
1686
|
+
if (outcome.kind === "OpOk") {
|
|
1687
|
+
return onOk(outcome.value);
|
|
1688
|
+
}
|
|
1689
|
+
if (outcome.kind === "OpErr") {
|
|
1690
|
+
return onErr(outcome.error);
|
|
1691
|
+
}
|
|
1692
|
+
return onNil();
|
|
1693
|
+
};
|
|
1694
|
+
Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "OpOk" ? outcome.value : defaultValue();
|
|
1695
|
+
Op2.map = (f) => (outcome) => outcome.kind === "OpOk" ? (0, Op2.ok)(f(outcome.value)) : outcome;
|
|
1696
|
+
Op2.mapError = (f) => (outcome) => outcome.kind === "OpErr" ? (0, Op2.err)(f(outcome.error)) : outcome;
|
|
1697
|
+
Op2.chain = (f) => (outcome) => outcome.kind === "OpOk" ? f(outcome.value) : outcome;
|
|
1698
|
+
Op2.tap = (f) => (outcome) => {
|
|
1699
|
+
if (outcome.kind === "OpOk") {
|
|
1700
|
+
f(outcome.value);
|
|
1701
|
+
}
|
|
1702
|
+
return outcome;
|
|
1703
|
+
};
|
|
1704
|
+
Op2.recover = (f) => (outcome) => outcome.kind === "OpErr" ? f(outcome.error) : outcome;
|
|
1705
|
+
let to;
|
|
1706
|
+
((to2) => {
|
|
1707
|
+
to2.Result = (onNil) => (outcome) => {
|
|
1708
|
+
if (outcome.kind === "OpOk") {
|
|
1709
|
+
return Result.make.ok(outcome.value);
|
|
1710
|
+
}
|
|
1711
|
+
if (outcome.kind === "OpErr") {
|
|
1712
|
+
return Result.make.err(outcome.error);
|
|
1713
|
+
}
|
|
1714
|
+
return Result.make.err(onNil());
|
|
1715
|
+
};
|
|
1716
|
+
to2.Maybe = (outcome) => outcome.kind === "OpOk" ? Maybe.make.some(outcome.value) : Maybe.make.none();
|
|
1717
|
+
})(to = Op2.to || (Op2.to = {}));
|
|
1718
|
+
Op2.all = (invocations) => Deferred.from.Promise(Promise.all(invocations.map(Deferred.to.Promise)));
|
|
1719
|
+
Op2.race = (invocations) => Deferred.from.Promise(Promise.race(invocations.map(Deferred.to.Promise)));
|
|
1720
|
+
Op2.wire = (source, f) => source.subscribe((state) => {
|
|
1721
|
+
if ((0, Op2.isOk)(state)) {
|
|
1722
|
+
f(state.value);
|
|
1723
|
+
}
|
|
1724
|
+
});
|
|
1725
|
+
function interpret(op, options) {
|
|
1726
|
+
const { strategy, retry: retryOptions, timeout: timeoutOptions } = options;
|
|
1727
|
+
switch (strategy) {
|
|
1728
|
+
case "once": {
|
|
1729
|
+
return makeOnce(op, retryOptions, timeoutOptions);
|
|
1730
|
+
}
|
|
1731
|
+
case "restartable": {
|
|
1732
|
+
return makeRestartable(op, options.minInterval, retryOptions, timeoutOptions);
|
|
1733
|
+
}
|
|
1734
|
+
case "exclusive": {
|
|
1735
|
+
return makeExclusive(op, options.cooldown, retryOptions, timeoutOptions);
|
|
1736
|
+
}
|
|
1737
|
+
case "queue": {
|
|
1738
|
+
return makeQueue(
|
|
1739
|
+
op,
|
|
1740
|
+
options.maxSize,
|
|
1741
|
+
options.overflow,
|
|
1742
|
+
options.concurrency,
|
|
1743
|
+
options.dedupe,
|
|
1744
|
+
retryOptions,
|
|
1745
|
+
timeoutOptions
|
|
1746
|
+
);
|
|
1747
|
+
}
|
|
1748
|
+
case "buffered": {
|
|
1749
|
+
return makeBuffered(op, options.size, retryOptions, timeoutOptions);
|
|
1750
|
+
}
|
|
1751
|
+
case "debounced": {
|
|
1752
|
+
return makeDebounced(
|
|
1753
|
+
op,
|
|
1754
|
+
options.duration,
|
|
1755
|
+
options.leading ?? false,
|
|
1756
|
+
options.maxWait,
|
|
1757
|
+
retryOptions,
|
|
1758
|
+
timeoutOptions
|
|
1759
|
+
);
|
|
1760
|
+
}
|
|
1761
|
+
case "throttled": {
|
|
1762
|
+
return makeThrottled(op, options.duration, options.trailing ?? false, retryOptions, timeoutOptions);
|
|
1763
|
+
}
|
|
1764
|
+
case "concurrent": {
|
|
1765
|
+
return makeConcurrent(
|
|
1766
|
+
op,
|
|
1767
|
+
options.n ?? 1,
|
|
1768
|
+
options.overflow ?? "drop",
|
|
1769
|
+
retryOptions,
|
|
1770
|
+
timeoutOptions
|
|
1771
|
+
);
|
|
1772
|
+
}
|
|
1773
|
+
case "keyed": {
|
|
1774
|
+
return makeKeyed(op, options.key ?? ((i) => i), options.perKey ?? "exclusive", timeoutOptions);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
Op2.interpret = interpret;
|
|
1779
|
+
})(Op || (Op = {}));
|
|
1780
|
+
|
|
1781
|
+
// src/Core/Optional.ts
|
|
1782
|
+
var Optional;
|
|
1783
|
+
((Optional2) => {
|
|
1784
|
+
let from;
|
|
1785
|
+
((from2) => {
|
|
1786
|
+
from2.accessors = (get2, set2) => ({
|
|
1787
|
+
get: get2,
|
|
1788
|
+
set: set2
|
|
1789
|
+
});
|
|
1790
|
+
from2.property = () => (key) => (0, from2.accessors)((s) => {
|
|
1791
|
+
const val = s[key];
|
|
1792
|
+
return val !== null && val !== void 0 ? Maybe.make.some(val) : Maybe.make.none();
|
|
1793
|
+
}, (a) => (s) => ({ ...s, [key]: a }));
|
|
1794
|
+
})(from = Optional2.from || (Optional2.from = {}));
|
|
1795
|
+
Optional2.index = (i) => from.accessors((arr) => i >= 0 && i < arr.length ? Maybe.make.some(arr[i]) : Maybe.make.none(), (a) => (arr) => {
|
|
1796
|
+
if (i < 0 || i >= arr.length) {
|
|
1797
|
+
return arr;
|
|
1798
|
+
}
|
|
1799
|
+
const copy = [...arr];
|
|
1800
|
+
copy[i] = a;
|
|
1801
|
+
return copy;
|
|
1802
|
+
});
|
|
1803
|
+
Optional2.get = (opt) => (s) => opt.get(s);
|
|
1804
|
+
Optional2.set = (opt) => (a) => (s) => opt.set(a)(s);
|
|
1805
|
+
Optional2.modify = (opt) => (f) => (s) => {
|
|
1806
|
+
const val = opt.get(s);
|
|
1807
|
+
return val.kind === "None" ? s : opt.set(f(val.value))(s);
|
|
1808
|
+
};
|
|
1809
|
+
Optional2.getOrElse = (opt) => (defaultValue) => (s) => {
|
|
1810
|
+
const val = opt.get(s);
|
|
1811
|
+
return val.kind === "Some" ? val.value : defaultValue();
|
|
1812
|
+
};
|
|
1813
|
+
Optional2.fold = (opt) => (onNone, onSome) => (s) => {
|
|
1814
|
+
const val = opt.get(s);
|
|
1815
|
+
return val.kind === "Some" ? onSome(val.value) : onNone();
|
|
1816
|
+
};
|
|
1817
|
+
Optional2.match = (opt) => (cases) => (s) => {
|
|
1818
|
+
const val = opt.get(s);
|
|
1819
|
+
return val.kind === "Some" ? cases.some(val.value) : cases.none();
|
|
1820
|
+
};
|
|
1821
|
+
Optional2.andThen = (inner) => (outer) => from.accessors((s) => {
|
|
1822
|
+
const mid = outer.get(s);
|
|
1823
|
+
return mid.kind === "None" ? Maybe.make.none() : inner.get(mid.value);
|
|
1824
|
+
}, (b) => (s) => {
|
|
1825
|
+
const mid = outer.get(s);
|
|
1826
|
+
return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
|
|
1827
|
+
});
|
|
1828
|
+
Optional2.andThenLens = (inner) => (outer) => from.accessors((s) => {
|
|
1829
|
+
const mid = outer.get(s);
|
|
1830
|
+
return mid.kind === "None" ? Maybe.make.none() : Maybe.make.some(inner.get(mid.value));
|
|
1831
|
+
}, (b) => (s) => {
|
|
1832
|
+
const mid = outer.get(s);
|
|
1833
|
+
return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
|
|
1834
|
+
});
|
|
1835
|
+
})(Optional || (Optional = {}));
|
|
1836
|
+
|
|
1837
|
+
// src/Core/Ordering.ts
|
|
1838
|
+
var Ordering;
|
|
1839
|
+
((Ordering3) => {
|
|
1840
|
+
Ordering3.string = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
1841
|
+
Ordering3.number = (a, b) => a - b;
|
|
1842
|
+
Ordering3.date = (a, b) => a.getTime() - b.getTime();
|
|
1843
|
+
Ordering3.reverse = (ord) => (a, b) => ord(b, a);
|
|
1844
|
+
Ordering3.thenBy = (ord2) => (ord1) => (a, b) => {
|
|
1845
|
+
const r = ord1(a, b);
|
|
1846
|
+
return r !== 0 ? r : ord2(a, b);
|
|
1847
|
+
};
|
|
1848
|
+
Ordering3.by = (f) => (ord) => (a, b) => ord(f(a), f(b));
|
|
1849
|
+
Ordering3.byFields = (orderings) => (a, b) => {
|
|
1850
|
+
for (let i = 0; i < orderings.length; i++) {
|
|
1851
|
+
const res = orderings[i](a, b);
|
|
1852
|
+
if (res !== 0) {
|
|
1853
|
+
return res;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
return 0;
|
|
1857
|
+
};
|
|
1858
|
+
Ordering3.tuple = (...orderings) => (a, b) => {
|
|
1859
|
+
const len = Math.min(a.length, b.length);
|
|
1860
|
+
for (let i = 0; i < len; i++) {
|
|
1861
|
+
const res = orderings[i](a[i], b[i]);
|
|
1862
|
+
if (res !== 0) {
|
|
1863
|
+
return res;
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
return a.length - b.length;
|
|
1867
|
+
};
|
|
1868
|
+
})(Ordering || (Ordering = {}));
|
|
1869
|
+
|
|
1870
|
+
// src/Core/Pair.ts
|
|
1871
|
+
var Pair;
|
|
1872
|
+
((Pair2) => {
|
|
1873
|
+
let from;
|
|
1874
|
+
((from2) => {
|
|
1875
|
+
from2.pair = (first2, second2) => [first2, second2];
|
|
1876
|
+
from2.array = (arr) => arr;
|
|
1877
|
+
})(from = Pair2.from || (Pair2.from = {}));
|
|
1878
|
+
Pair2.first = (p) => p[0];
|
|
1879
|
+
Pair2.second = (p) => p[1];
|
|
1880
|
+
Pair2.mapFirst = (f) => (p) => [f(p[0]), p[1]];
|
|
1881
|
+
Pair2.mapSecond = (f) => (p) => [p[0], f(p[1])];
|
|
1882
|
+
Pair2.mapBoth = (onFirst, onSecond) => (p) => [
|
|
1883
|
+
onFirst(p[0]),
|
|
1884
|
+
onSecond(p[1])
|
|
1885
|
+
];
|
|
1886
|
+
Pair2.fold = (f) => (p) => f(p[0], p[1]);
|
|
1887
|
+
Pair2.swap = (p) => [p[1], p[0]];
|
|
1888
|
+
let to;
|
|
1889
|
+
((to2) => {
|
|
1890
|
+
to2.Array = (p) => [...p];
|
|
1891
|
+
})(to = Pair2.to || (Pair2.to = {}));
|
|
1892
|
+
Pair2.tap = (f) => (p) => {
|
|
1893
|
+
f(p[0], p[1]);
|
|
1894
|
+
return p;
|
|
1895
|
+
};
|
|
1896
|
+
})(Pair || (Pair = {}));
|
|
1897
|
+
|
|
1898
|
+
// src/Core/Predicate.ts
|
|
1899
|
+
var Predicate;
|
|
1900
|
+
((Predicate2) => {
|
|
1901
|
+
Predicate2.not = (p) => (a) => !p(a);
|
|
1902
|
+
Predicate2.and = (second) => (first) => (a) => first(a) && second(a);
|
|
1903
|
+
Predicate2.or = (second) => (first) => (a) => first(a) || second(a);
|
|
1904
|
+
Predicate2.using = (f) => (p) => (b) => p(f(b));
|
|
1905
|
+
Predicate2.all = (predicates) => (a) => predicates.every((p) => p(a));
|
|
1906
|
+
Predicate2.any = (predicates) => (a) => predicates.some((p) => p(a));
|
|
1907
|
+
let from;
|
|
1908
|
+
((from2) => {
|
|
1909
|
+
from2.Refinement = (r) => r;
|
|
1910
|
+
})(from = Predicate2.from || (Predicate2.from = {}));
|
|
1911
|
+
Predicate2.match = (branches, fallback) => (a) => {
|
|
1912
|
+
for (let i = 0; i < branches.length; i++) {
|
|
1913
|
+
const [p, h] = branches[i];
|
|
1914
|
+
if (p(a)) {
|
|
1915
|
+
return h(a);
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
return fallback(a);
|
|
1919
|
+
};
|
|
1920
|
+
})(Predicate || (Predicate = {}));
|
|
1921
|
+
|
|
1922
|
+
// src/Core/Reader.ts
|
|
1923
|
+
var Reader;
|
|
1924
|
+
((Reader2) => {
|
|
1925
|
+
Reader2.resolve = (value) => (_env) => value;
|
|
1926
|
+
Reader2.ask = () => (env) => env;
|
|
1927
|
+
Reader2.asks = (f) => (env) => f(env);
|
|
1928
|
+
Reader2.map = (f) => (data) => (env) => f(data(env));
|
|
1929
|
+
Reader2.chain = (f) => (data) => (env) => f(data(env))(env);
|
|
1930
|
+
Reader2.ap = (arg) => (data) => (env) => data(env)(arg(env));
|
|
1931
|
+
Reader2.tap = (f) => (data) => (env) => {
|
|
1932
|
+
const a = data(env);
|
|
1933
|
+
f(a);
|
|
1934
|
+
return a;
|
|
1935
|
+
};
|
|
1936
|
+
Reader2.local = (f) => (data) => (env) => data(f(env));
|
|
1937
|
+
Reader2.run = (env) => (data) => data(env);
|
|
1938
|
+
Reader2.bindTo = (key) => (data) => (0, Reader2.map)((a) => ({ [key]: a }))(data);
|
|
1939
|
+
Reader2.bind = (key, f) => (data) => (0, Reader2.chain)(
|
|
1940
|
+
(a) => (0, Reader2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
1941
|
+
)(data);
|
|
1942
|
+
})(Reader || (Reader = {}));
|
|
1943
|
+
|
|
1944
|
+
// src/Core/Refinement.ts
|
|
1945
|
+
var Refinement;
|
|
1946
|
+
((Refinement2) => {
|
|
1947
|
+
let from;
|
|
1948
|
+
((from2) => {
|
|
1949
|
+
from2.predicate = (f) => f;
|
|
1950
|
+
})(from = Refinement2.from || (Refinement2.from = {}));
|
|
1951
|
+
Refinement2.compose = (bc) => (ab) => (a) => ab(a) && bc(a);
|
|
1952
|
+
Refinement2.and = (second) => (first) => (a) => first(a) && second(a);
|
|
1953
|
+
Refinement2.or = (second) => (first) => (a) => first(a) || second(a);
|
|
1954
|
+
let to;
|
|
1955
|
+
((to2) => {
|
|
1956
|
+
to2.Maybe = (r) => (a) => r(a) ? Maybe.make.some(a) : Maybe.make.none();
|
|
1957
|
+
to2.Result = (r, onFail) => (a) => r(a) ? Result.make.ok(a) : Result.make.err(onFail(a));
|
|
1958
|
+
})(to = Refinement2.to || (Refinement2.to = {}));
|
|
1959
|
+
})(Refinement || (Refinement = {}));
|
|
1960
|
+
|
|
1961
|
+
// src/Core/RemoteData.ts
|
|
1962
|
+
var _notAsked = { kind: "NotAsked" };
|
|
1963
|
+
var _loading = { kind: "Loading" };
|
|
1964
|
+
var RemoteData;
|
|
1965
|
+
((RemoteData2) => {
|
|
1966
|
+
let make;
|
|
1967
|
+
((make2) => {
|
|
1968
|
+
make2.notAsked = () => _notAsked;
|
|
1969
|
+
make2.loading = () => _loading;
|
|
1970
|
+
make2.failure = (error) => ({ kind: "Failure", error });
|
|
1971
|
+
make2.success = (value) => ({ kind: "Success", value });
|
|
1972
|
+
})(make = RemoteData2.make || (RemoteData2.make = {}));
|
|
1973
|
+
let is;
|
|
1974
|
+
((is2) => {
|
|
1975
|
+
is2.notAsked = (data) => data.kind === "NotAsked";
|
|
1976
|
+
is2.loading = (data) => data.kind === "Loading";
|
|
1977
|
+
is2.failure = (data) => data.kind === "Failure";
|
|
1978
|
+
is2.success = (data) => data.kind === "Success";
|
|
1979
|
+
})(is = RemoteData2.is || (RemoteData2.is = {}));
|
|
1980
|
+
RemoteData2.map = (f) => (data) => is.success(data) ? make.success(f(data.value)) : data;
|
|
1981
|
+
RemoteData2.mapError = (f) => (data) => is.failure(data) ? make.failure(f(data.error)) : data;
|
|
1982
|
+
RemoteData2.chain = (f) => (data) => is.success(data) ? f(data.value) : data;
|
|
1983
|
+
RemoteData2.ap = (arg) => (data) => {
|
|
1984
|
+
if (is.success(data) && is.success(arg)) {
|
|
1985
|
+
return make.success(data.value(arg.value));
|
|
1986
|
+
}
|
|
1987
|
+
if (is.failure(data)) {
|
|
1988
|
+
return data;
|
|
1989
|
+
}
|
|
1990
|
+
if (is.failure(arg)) {
|
|
1991
|
+
return arg;
|
|
1992
|
+
}
|
|
1993
|
+
if (is.loading(data) || is.loading(arg)) {
|
|
1994
|
+
return make.loading();
|
|
1995
|
+
}
|
|
1996
|
+
return make.notAsked();
|
|
1997
|
+
};
|
|
1998
|
+
RemoteData2.fold = (onFailure, onNotAsked, onLoading, onSuccess) => (data) => {
|
|
1999
|
+
switch (data.kind) {
|
|
2000
|
+
case "Failure": {
|
|
2001
|
+
return onFailure(data.error);
|
|
2002
|
+
}
|
|
2003
|
+
case "NotAsked": {
|
|
2004
|
+
return onNotAsked();
|
|
2005
|
+
}
|
|
2006
|
+
case "Loading": {
|
|
2007
|
+
return onLoading();
|
|
2008
|
+
}
|
|
2009
|
+
case "Success": {
|
|
2010
|
+
return onSuccess(data.value);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
};
|
|
2014
|
+
RemoteData2.match = (cases) => (data) => {
|
|
2015
|
+
switch (data.kind) {
|
|
2016
|
+
case "NotAsked": {
|
|
2017
|
+
return cases.notAsked();
|
|
2018
|
+
}
|
|
2019
|
+
case "Loading": {
|
|
2020
|
+
return cases.loading();
|
|
2021
|
+
}
|
|
2022
|
+
case "Failure": {
|
|
2023
|
+
return cases.failure(data.error);
|
|
2024
|
+
}
|
|
2025
|
+
case "Success": {
|
|
2026
|
+
return cases.success(data.value);
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
};
|
|
2030
|
+
RemoteData2.getOrElse = (defaultValue) => (data) => is.success(data) ? data.value : defaultValue();
|
|
2031
|
+
RemoteData2.tap = (f) => (data) => {
|
|
2032
|
+
if (is.success(data)) {
|
|
2033
|
+
f(data.value);
|
|
2034
|
+
}
|
|
2035
|
+
return data;
|
|
2036
|
+
};
|
|
2037
|
+
RemoteData2.tapError = (f) => (data) => {
|
|
2038
|
+
if (is.failure(data)) {
|
|
2039
|
+
f(data.error);
|
|
2040
|
+
}
|
|
2041
|
+
return data;
|
|
2042
|
+
};
|
|
2043
|
+
RemoteData2.recover = (fallback) => (data) => is.failure(data) ? fallback(data.error) : data;
|
|
2044
|
+
let to;
|
|
2045
|
+
((to2) => {
|
|
2046
|
+
to2.Maybe = (data) => is.success(data) ? Maybe.make.some(data.value) : Maybe.make.none();
|
|
2047
|
+
to2.Result = (onNotReady) => (data) => is.success(data) ? Result.make.ok(data.value) : Result.make.err(is.failure(data) ? data.error : onNotReady());
|
|
2048
|
+
})(to = RemoteData2.to || (RemoteData2.to = {}));
|
|
2049
|
+
let from;
|
|
2050
|
+
((from2) => {
|
|
2051
|
+
from2.Result = (data) => Result.is.ok(data) ? make.success(data.value) : make.failure(data.error);
|
|
2052
|
+
from2.Maybe = (onNone) => (data) => Maybe.is.some(data) ? make.success(data.value) : make.failure(onNone());
|
|
2053
|
+
})(from = RemoteData2.from || (RemoteData2.from = {}));
|
|
2054
|
+
RemoteData2.filter = (pred, onFalse) => (data) => is.success(data) ? pred(data.value) ? data : make.failure(onFalse(data.value)) : data;
|
|
2055
|
+
})(RemoteData || (RemoteData = {}));
|
|
2056
|
+
|
|
2057
|
+
// src/Core/Resource.ts
|
|
2058
|
+
var Resource;
|
|
2059
|
+
((Resource2) => {
|
|
2060
|
+
let from;
|
|
2061
|
+
((from2) => {
|
|
2062
|
+
from2.handlers = (acquire, release) => ({
|
|
2063
|
+
acquire,
|
|
2064
|
+
release
|
|
2065
|
+
});
|
|
2066
|
+
from2.Task = (acquire, release) => ({
|
|
2067
|
+
acquire: Task.map((a) => Result.make.ok(a))(acquire),
|
|
2068
|
+
release
|
|
2069
|
+
});
|
|
2070
|
+
})(from = Resource2.from || (Resource2.from = {}));
|
|
2071
|
+
Resource2.use = (f) => (resource) => (signal) => Deferred.from.Promise(
|
|
2072
|
+
Deferred.to.Promise(resource.acquire(signal)).then(async (acquired) => {
|
|
2073
|
+
if (Result.is.err(acquired)) {
|
|
2074
|
+
return acquired;
|
|
2075
|
+
}
|
|
2076
|
+
const a = acquired.value;
|
|
2077
|
+
try {
|
|
2078
|
+
const usageResult = await Deferred.to.Promise(f(a)(signal));
|
|
2079
|
+
return usageResult;
|
|
2080
|
+
} finally {
|
|
2081
|
+
await Deferred.to.Promise(resource.release(a)(signal));
|
|
2082
|
+
}
|
|
2083
|
+
})
|
|
2084
|
+
);
|
|
2085
|
+
Resource2.combine = (resourceA, resourceB) => ({
|
|
2086
|
+
acquire: (signal) => Deferred.from.Promise(
|
|
2087
|
+
Deferred.to.Promise(resourceA.acquire(signal)).then(async (acquiredA) => {
|
|
2088
|
+
if (Result.is.err(acquiredA)) {
|
|
2089
|
+
return acquiredA;
|
|
2090
|
+
}
|
|
2091
|
+
const a = acquiredA.value;
|
|
2092
|
+
const acquiredB = await Deferred.to.Promise(resourceB.acquire(signal));
|
|
2093
|
+
if (Result.is.err(acquiredB)) {
|
|
2094
|
+
await Deferred.to.Promise(resourceA.release(a)(signal));
|
|
2095
|
+
return acquiredB;
|
|
2096
|
+
}
|
|
2097
|
+
return Result.make.ok([a, acquiredB.value]);
|
|
2098
|
+
})
|
|
2099
|
+
),
|
|
2100
|
+
release: ([a, b]) => (signal) => Deferred.from.Promise(
|
|
2101
|
+
Deferred.to.Promise(resourceB.release(b)(signal)).then(() => Deferred.to.Promise(resourceA.release(a)(signal)))
|
|
2102
|
+
)
|
|
2103
|
+
});
|
|
2104
|
+
})(Resource || (Resource = {}));
|
|
2105
|
+
|
|
2106
|
+
// src/Core/Result.ts
|
|
2107
|
+
var Result;
|
|
2108
|
+
((Result4) => {
|
|
2109
|
+
let make;
|
|
2110
|
+
((make2) => {
|
|
2111
|
+
make2.ok = (value) => ({ kind: "Ok", value });
|
|
2112
|
+
make2.err = (e) => ({ kind: "Err", error: e });
|
|
2113
|
+
})(make = Result4.make || (Result4.make = {}));
|
|
2114
|
+
let is;
|
|
2115
|
+
((is2) => {
|
|
2116
|
+
is2.ok = (data) => data.kind === "Ok";
|
|
2117
|
+
is2.err = (data) => data.kind === "Err";
|
|
2118
|
+
})(is = Result4.is || (Result4.is = {}));
|
|
2119
|
+
Result4.tryCatch = (f, options) => {
|
|
2120
|
+
try {
|
|
2121
|
+
return make.ok(f());
|
|
2122
|
+
} catch (error) {
|
|
2123
|
+
return make.err(options.onError(error));
|
|
2124
|
+
}
|
|
2125
|
+
};
|
|
2126
|
+
Result4.map = (f) => (data) => is.ok(data) ? make.ok(f(data.value)) : data;
|
|
2127
|
+
Result4.mapError = (f) => (data) => is.err(data) ? make.err(f(data.error)) : data;
|
|
2128
|
+
Result4.chain = (f) => (data) => is.ok(data) ? f(data.value) : data;
|
|
2129
|
+
Result4.fold = (onErr, onOk) => (data) => is.ok(data) ? onOk(data.value) : onErr(data.error);
|
|
2130
|
+
Result4.match = (cases) => (data) => is.ok(data) ? cases.ok(data.value) : cases.err(data.error);
|
|
2131
|
+
Result4.getOrElse = (defaultValue) => (data) => is.ok(data) ? data.value : defaultValue();
|
|
2132
|
+
Result4.tap = (f) => (data) => {
|
|
2133
|
+
if (is.ok(data)) {
|
|
2134
|
+
f(data.value);
|
|
2135
|
+
}
|
|
2136
|
+
return data;
|
|
2137
|
+
};
|
|
2138
|
+
Result4.tapError = (f) => (data) => {
|
|
2139
|
+
if (is.err(data)) {
|
|
2140
|
+
f(data.error);
|
|
2141
|
+
}
|
|
2142
|
+
return data;
|
|
2143
|
+
};
|
|
2144
|
+
let from;
|
|
2145
|
+
((from2) => {
|
|
2146
|
+
from2.Predicate = (pred, onFalse) => (a) => pred(a) ? make.ok(a) : make.err(onFalse(a));
|
|
2147
|
+
from2.nullable = (onNull) => (value) => value === null || value === void 0 ? make.err(onNull()) : make.ok(value);
|
|
2148
|
+
from2.Maybe = (onNone) => (maybe) => Maybe.is.none(maybe) ? make.err(onNone()) : make.ok(maybe.value);
|
|
2149
|
+
from2.Validation = (combineErrors) => (val) => Validation.is.passed(val) ? make.ok(val.value) : make.err(combineErrors(val.errors));
|
|
2150
|
+
})(from = Result4.from || (Result4.from = {}));
|
|
2151
|
+
Result4.recover = (fallback) => (data) => is.ok(data) ? data : fallback(data.error);
|
|
2152
|
+
Result4.recoverUnless = (isBlocked, fallback) => (data) => is.err(data) && !isBlocked(data.error) ? fallback() : data;
|
|
2153
|
+
let to;
|
|
2154
|
+
((to2) => {
|
|
2155
|
+
to2.Maybe = (data) => is.ok(data) ? Maybe.make.some(data.value) : Maybe.make.none();
|
|
2156
|
+
to2.Validation = (data) => Validation.from.Result(data);
|
|
2157
|
+
})(to = Result4.to || (Result4.to = {}));
|
|
2158
|
+
Result4.transposeMaybe = (data) => is.err(data) ? Maybe.make.some(data) : Maybe.is.some(data.value) ? Maybe.make.some(make.ok(data.value.value)) : Maybe.make.none();
|
|
2159
|
+
Result4.ap = (arg) => (data) => is.ok(data) && is.ok(arg) ? make.ok(data.value(arg.value)) : is.err(data) ? data : arg;
|
|
2160
|
+
Result4.bindTo = (key) => (data) => (0, Result4.map)((a) => ({ [key]: a }))(data);
|
|
2161
|
+
Result4.bind = (key, f) => (data) => (0, Result4.chain)(
|
|
2162
|
+
(a) => (0, Result4.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
2163
|
+
)(data);
|
|
2164
|
+
Result4.struct = (fields) => {
|
|
2165
|
+
const result = {};
|
|
2166
|
+
for (const key in fields) {
|
|
2167
|
+
if (Object.hasOwn(fields, key)) {
|
|
2168
|
+
const res = fields[key];
|
|
2169
|
+
if (is.err(res)) {
|
|
2170
|
+
return res;
|
|
2171
|
+
}
|
|
2172
|
+
result[key] = res.value;
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
return make.ok(result);
|
|
2176
|
+
};
|
|
2177
|
+
Result4.ensure = (predicate, onFail) => (data) => is.err(data) ? data : predicate(data.value) ? data : make.err(onFail(data.value));
|
|
2178
|
+
Result4.bimap = (onErr, onOk) => (data) => is.ok(data) ? make.ok(onOk(data.value)) : make.err(onErr(data.error));
|
|
2179
|
+
})(Result || (Result = {}));
|
|
2180
|
+
|
|
2181
|
+
// src/Core/State.ts
|
|
2182
|
+
var State;
|
|
2183
|
+
((State2) => {
|
|
2184
|
+
State2.resolve = (value) => (s) => [value, s];
|
|
2185
|
+
State2.get = () => (s) => [s, s];
|
|
2186
|
+
State2.gets = (f) => (s) => [f(s), s];
|
|
2187
|
+
State2.put = (newState) => (_s) => [void 0, newState];
|
|
2188
|
+
State2.modify = (f) => (s) => [void 0, f(s)];
|
|
2189
|
+
State2.map = (f) => (st) => (s) => {
|
|
2190
|
+
const [a, s1] = st(s);
|
|
2191
|
+
return [f(a), s1];
|
|
2192
|
+
};
|
|
2193
|
+
State2.chain = (f) => (st) => (s) => {
|
|
2194
|
+
const [a, s1] = st(s);
|
|
2195
|
+
return f(a)(s1);
|
|
2196
|
+
};
|
|
2197
|
+
State2.ap = (arg) => (fn) => (s) => {
|
|
2198
|
+
const [f, s1] = fn(s);
|
|
2199
|
+
const [a, s2] = arg(s1);
|
|
2200
|
+
return [f(a), s2];
|
|
2201
|
+
};
|
|
2202
|
+
State2.tap = (f) => (st) => (s) => {
|
|
2203
|
+
const [a, s1] = st(s);
|
|
2204
|
+
f(a);
|
|
2205
|
+
return [a, s1];
|
|
2206
|
+
};
|
|
2207
|
+
State2.run = (initialState) => (st) => st(initialState);
|
|
2208
|
+
State2.evaluate = (initialState) => (st) => st(initialState)[0];
|
|
2209
|
+
State2.execute = (initialState) => (st) => st(initialState)[1];
|
|
2210
|
+
State2.bindTo = (key) => (data) => (0, State2.map)((a) => ({ [key]: a }))(data);
|
|
2211
|
+
State2.bind = (key, f) => (data) => (0, State2.chain)(
|
|
2212
|
+
(a) => (0, State2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
2213
|
+
)(data);
|
|
2214
|
+
State2.focus = (lens) => (stateOp) => (s) => {
|
|
2215
|
+
const subState = lens.get(s);
|
|
2216
|
+
const [b, newSubState] = stateOp(subState);
|
|
2217
|
+
return [b, lens.set(newSubState)(s)];
|
|
2218
|
+
};
|
|
2219
|
+
})(State || (State = {}));
|
|
2220
|
+
|
|
2221
|
+
// src/Core/Stream.ts
|
|
2222
|
+
var Stream;
|
|
2223
|
+
((Stream2) => {
|
|
2224
|
+
Stream2.make = (options) => ({
|
|
2225
|
+
options,
|
|
2226
|
+
_listeners: /* @__PURE__ */ new Set(),
|
|
2227
|
+
_queue: [],
|
|
2228
|
+
_isEmitting: false
|
|
2229
|
+
});
|
|
2230
|
+
Stream2.emit = (target, message) => {
|
|
2231
|
+
const targets = Array.isArray(target) ? target : [target];
|
|
2232
|
+
const msg = message;
|
|
2233
|
+
for (const stream of targets) {
|
|
2234
|
+
stream._queue.push(msg);
|
|
2235
|
+
if (!stream._isEmitting) {
|
|
2236
|
+
stream._isEmitting = true;
|
|
2237
|
+
try {
|
|
2238
|
+
while (stream._queue.length > 0) {
|
|
2239
|
+
const nextMsg = stream._queue.shift();
|
|
2240
|
+
const listeners = Array.from(stream._listeners);
|
|
2241
|
+
for (const listener of listeners) {
|
|
2242
|
+
try {
|
|
2243
|
+
listener(nextMsg);
|
|
2244
|
+
} catch (err2) {
|
|
2245
|
+
if (stream.options?.onError) {
|
|
2246
|
+
stream.options.onError(err2);
|
|
2247
|
+
} else {
|
|
2248
|
+
throw err2;
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
} finally {
|
|
2254
|
+
stream._isEmitting = false;
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
};
|
|
2259
|
+
Stream2.forward = (options) => {
|
|
2260
|
+
const targets = Array.isArray(options.to) ? options.to : [options.to];
|
|
2261
|
+
const filterSet = options.only ? new Set(options.only) : null;
|
|
2262
|
+
const handler = (msg) => {
|
|
2263
|
+
if (filterSet !== null && !filterSet.has(msg.kind)) {
|
|
2264
|
+
return;
|
|
2265
|
+
}
|
|
2266
|
+
for (const target of targets) {
|
|
2267
|
+
(0, Stream2.emit)(target, msg);
|
|
2268
|
+
}
|
|
2269
|
+
};
|
|
2270
|
+
options.from._listeners.add(handler);
|
|
2271
|
+
return () => {
|
|
2272
|
+
options.from._listeners.delete(handler);
|
|
2273
|
+
};
|
|
2274
|
+
};
|
|
2275
|
+
Stream2.listen = (stream, events, options) => {
|
|
2276
|
+
const eventList = Array.isArray(events) ? events : [events];
|
|
2277
|
+
const isOrdered = options?.ordered ?? false;
|
|
2278
|
+
const isStrict = options?.strict ?? false;
|
|
2279
|
+
const isOnce = options?.once ?? false;
|
|
2280
|
+
const resetKinds = options?.reset ? new Set(Array.isArray(options.reset) ? options.reset : [options.reset]) : null;
|
|
2281
|
+
const optionalKinds = options?.optional ? new Set(Array.isArray(options.optional) ? options.optional : [options.optional]) : null;
|
|
2282
|
+
const createMatcher = (onMatch) => {
|
|
2283
|
+
let sequenceIndex = 0;
|
|
2284
|
+
return (msg) => {
|
|
2285
|
+
if (resetKinds !== null && resetKinds.has(msg.kind)) {
|
|
2286
|
+
sequenceIndex = 0;
|
|
2287
|
+
return;
|
|
2288
|
+
}
|
|
2289
|
+
if (!isOrdered) {
|
|
2290
|
+
if (eventList.includes(msg.kind)) {
|
|
2291
|
+
onMatch(msg);
|
|
2292
|
+
}
|
|
2293
|
+
return;
|
|
2294
|
+
}
|
|
2295
|
+
let expectedKind = eventList[sequenceIndex];
|
|
2296
|
+
if (expectedKind !== msg.kind && optionalKinds !== null) {
|
|
2297
|
+
let lookaheadIndex = sequenceIndex;
|
|
2298
|
+
while (lookaheadIndex < eventList.length && optionalKinds.has(eventList[lookaheadIndex]) && eventList[lookaheadIndex] !== msg.kind) {
|
|
2299
|
+
lookaheadIndex++;
|
|
2300
|
+
}
|
|
2301
|
+
if (lookaheadIndex < eventList.length && eventList[lookaheadIndex] === msg.kind) {
|
|
2302
|
+
sequenceIndex = lookaheadIndex;
|
|
2303
|
+
expectedKind = eventList[sequenceIndex];
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
if (msg.kind === expectedKind) {
|
|
2307
|
+
sequenceIndex++;
|
|
2308
|
+
if (sequenceIndex === eventList.length) {
|
|
2309
|
+
sequenceIndex = 0;
|
|
2310
|
+
onMatch(msg);
|
|
2311
|
+
}
|
|
2312
|
+
} else if (isStrict) {
|
|
2313
|
+
sequenceIndex = msg.kind === eventList[0] ? 1 : 0;
|
|
2314
|
+
} else if (eventList.includes(msg.kind)) {
|
|
2315
|
+
sequenceIndex = msg.kind === eventList[0] ? 1 : 0;
|
|
2316
|
+
}
|
|
2317
|
+
};
|
|
2318
|
+
};
|
|
2319
|
+
return {
|
|
2320
|
+
reduce: (reducer, initialState) => {
|
|
2321
|
+
let currentState = initialState;
|
|
2322
|
+
const listenerFn = createMatcher((msg) => {
|
|
2323
|
+
currentState = reducer(msg, currentState);
|
|
2324
|
+
if (isOnce) {
|
|
2325
|
+
stream._listeners.delete(listenerFn);
|
|
2326
|
+
}
|
|
2327
|
+
});
|
|
2328
|
+
const unsubscribe = () => {
|
|
2329
|
+
stream._listeners.delete(listenerFn);
|
|
2330
|
+
};
|
|
2331
|
+
stream._listeners.add(listenerFn);
|
|
2332
|
+
return { unsubscribe, getState: () => currentState };
|
|
2333
|
+
},
|
|
2334
|
+
tap: (effect) => {
|
|
2335
|
+
const listenerFn = createMatcher((msg) => {
|
|
2336
|
+
effect(msg);
|
|
2337
|
+
if (isOnce) {
|
|
2338
|
+
stream._listeners.delete(listenerFn);
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
const unsubscribe = () => {
|
|
2342
|
+
stream._listeners.delete(listenerFn);
|
|
2343
|
+
};
|
|
2344
|
+
stream._listeners.add(listenerFn);
|
|
2345
|
+
return unsubscribe;
|
|
2346
|
+
}
|
|
2347
|
+
};
|
|
2348
|
+
};
|
|
2349
|
+
})(Stream || (Stream = {}));
|
|
2350
|
+
|
|
2351
|
+
// src/Core/TaskMaybe.ts
|
|
2352
|
+
var TaskMaybe;
|
|
2353
|
+
((TaskMaybe2) => {
|
|
2354
|
+
let make;
|
|
2355
|
+
((make2) => {
|
|
2356
|
+
make2.some = (value) => Task.resolve(Maybe.make.some(value));
|
|
2357
|
+
make2.none = () => Task.resolve(Maybe.make.none());
|
|
2358
|
+
})(make = TaskMaybe2.make || (TaskMaybe2.make = {}));
|
|
2359
|
+
({ some: TaskMaybe2.some } = make);
|
|
2360
|
+
({ none: TaskMaybe2.none } = make);
|
|
2361
|
+
let from;
|
|
2362
|
+
((from2) => {
|
|
2363
|
+
from2.Maybe = (option) => Task.resolve(option);
|
|
2364
|
+
from2.nullable = (value) => Task.resolve(Maybe.from.nullable(value));
|
|
2365
|
+
from2.Result = (result) => Task.resolve(Result.to.Maybe(result));
|
|
2366
|
+
from2.Task = (task) => Task.map(Maybe.make.some)(task);
|
|
2367
|
+
})(from = TaskMaybe2.from || (TaskMaybe2.from = {}));
|
|
2368
|
+
TaskMaybe2.tryCatch = (f) => (signal) => Deferred.from.Promise(Promise.resolve(f(signal)).then(Maybe.make.some).catch(() => Maybe.make.none()));
|
|
2369
|
+
TaskMaybe2.map = (f) => (data) => Task.map(Maybe.map(f))(data);
|
|
2370
|
+
TaskMaybe2.chain = (f) => (data) => Task.chain(
|
|
2371
|
+
(option) => Maybe.is.some(option) ? f(option.value) : Task.resolve(Maybe.make.none())
|
|
2372
|
+
)(data);
|
|
2373
|
+
TaskMaybe2.ap = (arg) => (data) => (signal) => Deferred.from.Promise(
|
|
2374
|
+
Promise.all([Deferred.to.Promise(data(signal)), Deferred.to.Promise(arg(signal))]).then(
|
|
2375
|
+
([of_, oa]) => Maybe.ap(oa)(of_)
|
|
2376
|
+
)
|
|
2377
|
+
);
|
|
2378
|
+
TaskMaybe2.fold = (onNone, onSome) => (data) => Task.map(Maybe.fold(onNone, onSome))(data);
|
|
2379
|
+
TaskMaybe2.match = (cases) => (data) => Task.map(Maybe.match(cases))(data);
|
|
2380
|
+
TaskMaybe2.getOrElse = (defaultValue) => (data) => Task.map(Maybe.getOrElse(defaultValue))(data);
|
|
2381
|
+
TaskMaybe2.tap = (f) => (data) => Task.map(Maybe.tap(f))(data);
|
|
2382
|
+
TaskMaybe2.filter = (predicate) => (data) => Task.map(Maybe.filter(predicate))(data);
|
|
2383
|
+
let to;
|
|
2384
|
+
((to2) => {
|
|
2385
|
+
to2.Result = (onNone) => (data) => Task.map(Maybe.to.Result(onNone))(data);
|
|
2386
|
+
})(to = TaskMaybe2.to || (TaskMaybe2.to = {}));
|
|
2387
|
+
TaskMaybe2.bindTo = (key) => (data) => (0, TaskMaybe2.map)((a) => ({ [key]: a }))(data);
|
|
2388
|
+
TaskMaybe2.bind = (key, f) => (data) => (0, TaskMaybe2.chain)(
|
|
2389
|
+
(a) => (0, TaskMaybe2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
2390
|
+
)(data);
|
|
2391
|
+
TaskMaybe2.recover = (fallback) => (data) => Task.chain((maybe) => Maybe.is.none(maybe) ? fallback() : Task.resolve(maybe))(
|
|
2392
|
+
data
|
|
2393
|
+
);
|
|
2394
|
+
TaskMaybe2.struct = (fields) => (signal) => Deferred.from.Promise((() => {
|
|
2395
|
+
const keys = Object.keys(fields);
|
|
2396
|
+
const promises = keys.map((key) => Deferred.to.Promise(fields[key](signal)));
|
|
2397
|
+
return Promise.all(promises).then((results) => {
|
|
2398
|
+
const record = {};
|
|
2399
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2400
|
+
const res = results[i];
|
|
2401
|
+
if (Maybe.is.none(res)) {
|
|
2402
|
+
return res;
|
|
2403
|
+
}
|
|
2404
|
+
record[keys[i]] = res.value;
|
|
2405
|
+
}
|
|
2406
|
+
return Maybe.make.some(record);
|
|
2407
|
+
});
|
|
2408
|
+
})());
|
|
2409
|
+
TaskMaybe2.memoize = (task) => Task.memoize(task);
|
|
2410
|
+
})(TaskMaybe || (TaskMaybe = {}));
|
|
2411
|
+
|
|
2412
|
+
// src/Core/TaskResult.ts
|
|
2413
|
+
var TaskResult;
|
|
2414
|
+
((TaskResult2) => {
|
|
2415
|
+
let make;
|
|
2416
|
+
((make2) => {
|
|
2417
|
+
make2.ok = (value) => Task.resolve(Result.make.ok(value));
|
|
2418
|
+
make2.err = (error) => Task.resolve(Result.make.err(error));
|
|
2419
|
+
})(make = TaskResult2.make || (TaskResult2.make = {}));
|
|
2420
|
+
({ ok: TaskResult2.ok } = make);
|
|
2421
|
+
({ err: TaskResult2.err } = make);
|
|
2422
|
+
let from;
|
|
2423
|
+
((from2) => {
|
|
2424
|
+
from2.nullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.make.err(onNull()) : Result.make.ok(value));
|
|
2425
|
+
from2.Maybe = (onNone) => (maybe) => Task.resolve(Maybe.is.none(maybe) ? Result.make.err(onNone()) : Result.make.ok(maybe.value));
|
|
2426
|
+
from2.Result = (result) => Task.resolve(result);
|
|
2427
|
+
})(from = TaskResult2.from || (TaskResult2.from = {}));
|
|
2428
|
+
let to;
|
|
2429
|
+
((to2) => {
|
|
2430
|
+
to2.Maybe = (data) => Task.map(Result.to.Maybe)(data);
|
|
2431
|
+
})(to = TaskResult2.to || (TaskResult2.to = {}));
|
|
2432
|
+
TaskResult2.tryCatch = (f, options) => (signal) => Deferred.from.Promise(
|
|
2433
|
+
globalThis.Promise.resolve().then(async () => f(signal)).then(Result.make.ok).catch(
|
|
2434
|
+
(error) => Result.make.err(options.onError(error))
|
|
2435
|
+
)
|
|
2436
|
+
);
|
|
2437
|
+
TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
|
|
2438
|
+
TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
|
|
2439
|
+
TaskResult2.chain = (f) => (data) => Task.chain(
|
|
2440
|
+
(result) => Result.is.ok(result) ? f(result.value) : Task.resolve(Result.make.err(result.error))
|
|
2441
|
+
)(data);
|
|
2442
|
+
TaskResult2.fold = (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data);
|
|
2443
|
+
TaskResult2.match = (cases) => (data) => Task.map(Result.match(cases))(data);
|
|
2444
|
+
TaskResult2.recover = (fallback) => (data) => Task.chain(
|
|
2445
|
+
(result) => Result.is.err(result) ? fallback(result.error) : Task.resolve(result)
|
|
2446
|
+
)(data);
|
|
2447
|
+
TaskResult2.recoverUnless = (isBlocked, fallback) => (data) => Task.chain(
|
|
2448
|
+
(result) => Result.is.err(result) && !isBlocked(result.error) ? fallback(result.error) : Task.resolve(result)
|
|
2449
|
+
)(data);
|
|
2450
|
+
TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
|
|
2451
|
+
TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
|
|
2452
|
+
TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
|
|
2453
|
+
TaskResult2.ap = (arg) => (data) => (signal) => Deferred.from.Promise(
|
|
2454
|
+
Promise.all([Deferred.to.Promise(data(signal)), Deferred.to.Promise(arg(signal))]).then(
|
|
2455
|
+
([of_, oa]) => Result.ap(oa)(of_)
|
|
2456
|
+
)
|
|
2457
|
+
);
|
|
2458
|
+
TaskResult2.run = (signal) => (task) => task(signal);
|
|
2459
|
+
TaskResult2.bindTo = (key) => (data) => (0, TaskResult2.map)((a) => ({ [key]: a }))(data);
|
|
2460
|
+
TaskResult2.bind = (key, f) => (data) => (0, TaskResult2.chain)(
|
|
2461
|
+
(a) => (0, TaskResult2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
2462
|
+
)(data);
|
|
2463
|
+
TaskResult2.struct = (fields) => (signal) => Deferred.from.Promise((() => {
|
|
2464
|
+
const keys = Object.keys(fields);
|
|
2465
|
+
const promises = keys.map((key) => Deferred.to.Promise(fields[key](signal)));
|
|
2466
|
+
return Promise.all(promises).then((results) => {
|
|
2467
|
+
const record = {};
|
|
2468
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2469
|
+
const res = results[i];
|
|
2470
|
+
if (Result.is.err(res)) {
|
|
2471
|
+
return res;
|
|
2472
|
+
}
|
|
2473
|
+
record[keys[i]] = res.value;
|
|
2474
|
+
}
|
|
2475
|
+
return Result.make.ok(record);
|
|
2476
|
+
});
|
|
2477
|
+
})());
|
|
2478
|
+
TaskResult2.retry = (policy) => (task) => (signal) => Deferred.from.Promise((() => {
|
|
2479
|
+
const { attempts } = policy;
|
|
2480
|
+
const wait = (duration) => new Promise((res) => {
|
|
2481
|
+
let timerId;
|
|
2482
|
+
const onAbort = () => {
|
|
2483
|
+
clearTimeout(timerId);
|
|
2484
|
+
res();
|
|
2485
|
+
};
|
|
2486
|
+
if (signal) {
|
|
2487
|
+
if (signal.aborted) {
|
|
2488
|
+
return res();
|
|
2489
|
+
}
|
|
2490
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2491
|
+
}
|
|
2492
|
+
timerId = setTimeout(() => {
|
|
2493
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2494
|
+
res();
|
|
2495
|
+
}, Duration.to.milliseconds(duration));
|
|
2496
|
+
});
|
|
2497
|
+
const executeAttempt = (attempt) => Deferred.to.Promise(task(signal)).then((res) => {
|
|
2498
|
+
if (Result.is.ok(res) || attempt >= attempts || signal?.aborted) {
|
|
2499
|
+
return res;
|
|
2500
|
+
}
|
|
2501
|
+
const delay = policy.getDelay(attempt);
|
|
2502
|
+
return wait(delay).then(() => executeAttempt(attempt + 1));
|
|
2503
|
+
});
|
|
2504
|
+
return executeAttempt(1);
|
|
2505
|
+
})());
|
|
2506
|
+
TaskResult2.memoize = (task) => Task.memoize(task);
|
|
2507
|
+
TaskResult2.timeout = (options) => (task) => (signal) => Deferred.from.Promise(
|
|
2508
|
+
new Promise((resolve) => {
|
|
2509
|
+
const ms = Duration.to.milliseconds(options.duration);
|
|
2510
|
+
let timerId;
|
|
2511
|
+
const onAbort = () => {
|
|
2512
|
+
clearTimeout(timerId);
|
|
2513
|
+
};
|
|
2514
|
+
if (signal) {
|
|
2515
|
+
if (signal.aborted) {
|
|
2516
|
+
return Deferred.to.Promise(task(signal)).then(resolve);
|
|
2517
|
+
}
|
|
2518
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2519
|
+
}
|
|
2520
|
+
timerId = setTimeout(() => {
|
|
2521
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2522
|
+
resolve(Result.make.err(options.onTimeout()));
|
|
2523
|
+
}, ms);
|
|
2524
|
+
Deferred.to.Promise(task(signal)).then((res) => {
|
|
2525
|
+
clearTimeout(timerId);
|
|
2526
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2527
|
+
resolve(res);
|
|
2528
|
+
});
|
|
2529
|
+
})
|
|
2530
|
+
);
|
|
2531
|
+
TaskResult2.allSettled = (tasks) => (signal) => Deferred.from.Promise(Promise.all(tasks.map((task) => Deferred.to.Promise(task(signal)))));
|
|
2532
|
+
})(TaskResult || (TaskResult = {}));
|
|
2533
|
+
|
|
2534
|
+
// src/internal/InternalTypes.ts
|
|
2535
|
+
var isNonEmptyArr = (list) => list.length > 0;
|
|
2536
|
+
|
|
2537
|
+
// src/Core/TaskValidation.ts
|
|
2538
|
+
var TaskValidation;
|
|
2539
|
+
((TaskValidation2) => {
|
|
2540
|
+
let make;
|
|
2541
|
+
((make2) => {
|
|
2542
|
+
make2.passed = (value) => Task.resolve(Validation.make.passed(value));
|
|
2543
|
+
make2.failed = (error) => Task.resolve(Validation.make.failed(error));
|
|
2544
|
+
make2.failedAll = (errors) => Task.resolve(Validation.make.failedAll(errors));
|
|
2545
|
+
})(make = TaskValidation2.make || (TaskValidation2.make = {}));
|
|
2546
|
+
({ passed: TaskValidation2.passed } = make);
|
|
2547
|
+
({ failed: TaskValidation2.failed } = make);
|
|
2548
|
+
({ failedAll: TaskValidation2.failedAll } = make);
|
|
2549
|
+
let from;
|
|
2550
|
+
((from2) => {
|
|
2551
|
+
from2.Validation = (validation) => Task.resolve(validation);
|
|
2552
|
+
from2.nullable = (onNull) => (value) => Task.resolve(
|
|
2553
|
+
value === null || value === void 0 ? Validation.make.failed(onNull()) : Validation.make.passed(value)
|
|
2554
|
+
);
|
|
2555
|
+
from2.Maybe = (onNone) => (maybe) => Task.resolve(
|
|
2556
|
+
Maybe.is.none(maybe) ? Validation.make.failed(onNone()) : Validation.make.passed(maybe.value)
|
|
2557
|
+
);
|
|
2558
|
+
from2.Result = (result) => Task.resolve(Validation.from.Result(result));
|
|
2559
|
+
})(from = TaskValidation2.from || (TaskValidation2.from = {}));
|
|
2560
|
+
let to;
|
|
2561
|
+
((to2) => {
|
|
2562
|
+
to2.Result = (combineErrors) => (data) => Task.map(Validation.to.Result(combineErrors))(data);
|
|
2563
|
+
to2.Maybe = (data) => Task.map(Validation.to.Maybe)(data);
|
|
2564
|
+
})(to = TaskValidation2.to || (TaskValidation2.to = {}));
|
|
2565
|
+
TaskValidation2.tryCatch = (f, options) => (signal) => Deferred.from.Promise(
|
|
2566
|
+
globalThis.Promise.resolve().then(async () => f(signal)).then(Validation.make.passed).catch(
|
|
2567
|
+
(error) => Validation.make.failed(options.onError(error))
|
|
2568
|
+
)
|
|
2569
|
+
);
|
|
2570
|
+
TaskValidation2.map = (f) => (data) => Task.map(Validation.map(f))(data);
|
|
2571
|
+
TaskValidation2.ap = (arg) => (data) => (signal) => Deferred.from.Promise(
|
|
2572
|
+
Promise.all([Deferred.to.Promise(data(signal)), Deferred.to.Promise(arg(signal))]).then(
|
|
2573
|
+
([vf, va]) => Validation.ap(va)(vf)
|
|
2574
|
+
)
|
|
2575
|
+
);
|
|
2576
|
+
TaskValidation2.fold = (onFailed, onPassed) => (data) => Task.map(Validation.fold(onFailed, onPassed))(data);
|
|
2577
|
+
TaskValidation2.match = (cases) => (data) => Task.map(Validation.match(cases))(data);
|
|
2578
|
+
TaskValidation2.getOrElse = (defaultValue) => (data) => Task.map(Validation.getOrElse(defaultValue))(data);
|
|
2579
|
+
TaskValidation2.tap = (f) => (data) => Task.map(Validation.tap(f))(data);
|
|
2580
|
+
TaskValidation2.recover = (fallback) => (data) => Task.chain(
|
|
2581
|
+
(validation) => Validation.is.passed(validation) ? Task.resolve(validation) : fallback(validation.errors)
|
|
2582
|
+
)(data);
|
|
2583
|
+
TaskValidation2.recoverUnless = (isBlocked, fallback) => (data) => Task.chain(
|
|
2584
|
+
(validation) => Validation.is.passed(validation) ? Task.resolve(validation) : isBlocked(validation.errors) ? Task.resolve(validation) : fallback(validation.errors)
|
|
2585
|
+
)(data);
|
|
2586
|
+
TaskValidation2.product = (first, second) => (signal) => Deferred.from.Promise(
|
|
2587
|
+
Promise.all([Deferred.to.Promise(first(signal)), Deferred.to.Promise(second(signal))]).then(
|
|
2588
|
+
([va, vb]) => Validation.product(va, vb)
|
|
2589
|
+
)
|
|
2590
|
+
);
|
|
2591
|
+
TaskValidation2.productAll = (data) => (signal) => Deferred.from.Promise(
|
|
2592
|
+
Promise.all(data.map((t) => Deferred.to.Promise(t(signal)))).then((results) => {
|
|
2593
|
+
const [first, ...rest] = results;
|
|
2594
|
+
return Validation.productAll([first, ...rest]);
|
|
2595
|
+
})
|
|
2596
|
+
);
|
|
2597
|
+
TaskValidation2.mapError = (f) => (data) => Task.map(Validation.mapError(f))(data);
|
|
2598
|
+
TaskValidation2.tapError = (f) => (data) => Task.map(Validation.tapError(f))(data);
|
|
2599
|
+
TaskValidation2.struct = (fields) => (signal) => Deferred.from.Promise((() => {
|
|
2600
|
+
const keys = Object.keys(fields);
|
|
2601
|
+
const promises = keys.map((key) => Deferred.to.Promise(fields[key](signal)));
|
|
2602
|
+
return Promise.all(promises).then((results) => {
|
|
2603
|
+
const record = {};
|
|
2604
|
+
const errors = [];
|
|
2605
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2606
|
+
const res = results[i];
|
|
2607
|
+
if (Validation.is.passed(res)) {
|
|
2608
|
+
record[keys[i]] = res.value;
|
|
2609
|
+
} else {
|
|
2610
|
+
errors.push(...res.errors);
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
return isNonEmptyArr(errors) ? Validation.make.failedAll(errors) : Validation.make.passed(record);
|
|
2614
|
+
});
|
|
2615
|
+
})());
|
|
2616
|
+
TaskValidation2.memoize = (task) => Task.memoize(task);
|
|
2617
|
+
})(TaskValidation || (TaskValidation = {}));
|
|
2618
|
+
|
|
2619
|
+
// src/Core/Task.ts
|
|
2620
|
+
var toPromise = (task, signal) => Deferred.to.Promise(task(signal));
|
|
2621
|
+
var fromPromise = (f) => (signal) => Deferred.from.Promise(f(signal));
|
|
2622
|
+
var getMs2 = (duration) => Duration.to.milliseconds(duration);
|
|
2623
|
+
var Task;
|
|
2624
|
+
((Task2) => {
|
|
2625
|
+
Task2.resolve = (value) => () => Deferred.from.Promise(globalThis.Promise.resolve(value));
|
|
2626
|
+
let from;
|
|
2627
|
+
((from2) => {
|
|
2628
|
+
from2.sync = (f) => () => Deferred.from.Promise(globalThis.Promise.resolve(f()));
|
|
2629
|
+
})(from = Task2.from || (Task2.from = {}));
|
|
2630
|
+
Task2.tryCatch = (f, options) => fromPromise((signal) => globalThis.Promise.resolve().then(() => f(signal)).catch((err2) => options.onError(err2)));
|
|
2631
|
+
Task2.map = (f) => (data) => fromPromise((signal) => toPromise(data, signal).then(f));
|
|
2632
|
+
Task2.chain = (f) => (data) => fromPromise((signal) => toPromise(data, signal).then((a) => toPromise(f(a), signal)));
|
|
2633
|
+
Task2.ap = (arg) => (data) => fromPromise((signal) => Promise.all([toPromise(data, signal), toPromise(arg, signal)]).then(([f, a]) => f(a)));
|
|
2634
|
+
Task2.tap = (f) => (data) => fromPromise(
|
|
2635
|
+
(signal) => toPromise(data, signal).then((a) => {
|
|
2636
|
+
f(a);
|
|
2637
|
+
return a;
|
|
2638
|
+
})
|
|
2639
|
+
);
|
|
2640
|
+
Task2.all = (tasks) => fromPromise(
|
|
2641
|
+
(signal) => Promise.all(tasks.map((t) => toPromise(t, signal)))
|
|
2642
|
+
);
|
|
2643
|
+
Task2.delay = (duration) => (data) => fromPromise(
|
|
2644
|
+
(signal) => new Promise((res) => {
|
|
2645
|
+
let timerId;
|
|
2646
|
+
const onAbort = () => {
|
|
2647
|
+
clearTimeout(timerId);
|
|
2648
|
+
res(toPromise(data, signal));
|
|
2649
|
+
};
|
|
2650
|
+
if (signal) {
|
|
2651
|
+
if (signal.aborted) {
|
|
2652
|
+
return res(toPromise(data, signal));
|
|
2653
|
+
}
|
|
2654
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2655
|
+
}
|
|
2656
|
+
timerId = setTimeout(() => {
|
|
2657
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2658
|
+
res(toPromise(data, signal));
|
|
2659
|
+
}, getMs2(duration));
|
|
2660
|
+
})
|
|
2661
|
+
);
|
|
2662
|
+
Task2.repeat = (options) => (task) => fromPromise((signal) => {
|
|
2663
|
+
const { times, delay: delayDuration } = options;
|
|
2664
|
+
if (times <= 0) {
|
|
2665
|
+
return Promise.resolve([]);
|
|
2666
|
+
}
|
|
2667
|
+
const results = [];
|
|
2668
|
+
const wait = () => new Promise((r) => {
|
|
2669
|
+
let timerId;
|
|
2670
|
+
const onAbort = () => {
|
|
2671
|
+
clearTimeout(timerId);
|
|
2672
|
+
r();
|
|
2673
|
+
};
|
|
2674
|
+
if (signal) {
|
|
2675
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2676
|
+
}
|
|
2677
|
+
timerId = setTimeout(() => {
|
|
2678
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2679
|
+
r();
|
|
2680
|
+
}, delayDuration ? getMs2(delayDuration) : 0);
|
|
2681
|
+
});
|
|
2682
|
+
const run2 = (left) => {
|
|
2683
|
+
if (signal?.aborted) {
|
|
2684
|
+
return Promise.resolve(results);
|
|
2685
|
+
}
|
|
2686
|
+
return toPromise(task, signal).then((a) => {
|
|
2687
|
+
results.push(a);
|
|
2688
|
+
if (left <= 1 || signal?.aborted) {
|
|
2689
|
+
return results;
|
|
2690
|
+
}
|
|
2691
|
+
return wait().then(() => run2(left - 1));
|
|
2692
|
+
});
|
|
2693
|
+
};
|
|
2694
|
+
return run2(times);
|
|
2695
|
+
});
|
|
2696
|
+
Task2.repeatUntil = (options) => (task) => fromPromise((signal) => {
|
|
2697
|
+
const { when: predicate, delay: delayDuration, maxAttempts } = options;
|
|
2698
|
+
const wait = () => new Promise((r) => {
|
|
2699
|
+
let timerId;
|
|
2700
|
+
const onAbort = () => {
|
|
2701
|
+
clearTimeout(timerId);
|
|
2702
|
+
r();
|
|
2703
|
+
};
|
|
2704
|
+
if (signal) {
|
|
2705
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2706
|
+
}
|
|
2707
|
+
timerId = setTimeout(() => {
|
|
2708
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2709
|
+
r();
|
|
2710
|
+
}, delayDuration ? getMs2(delayDuration) : 0);
|
|
2711
|
+
});
|
|
2712
|
+
const run2 = (attempt, lastValue) => {
|
|
2713
|
+
if (signal?.aborted && lastValue !== void 0) {
|
|
2714
|
+
return Promise.resolve(lastValue);
|
|
2715
|
+
}
|
|
2716
|
+
return toPromise(task, signal).then((a) => {
|
|
2717
|
+
if (predicate(a)) {
|
|
2718
|
+
return a;
|
|
2719
|
+
}
|
|
2720
|
+
if (maxAttempts !== void 0 && attempt >= maxAttempts) {
|
|
2721
|
+
return a;
|
|
2722
|
+
}
|
|
2723
|
+
if (signal?.aborted) {
|
|
2724
|
+
return a;
|
|
2725
|
+
}
|
|
2726
|
+
return wait().then(() => run2(attempt + 1, a));
|
|
2727
|
+
});
|
|
2728
|
+
};
|
|
2729
|
+
return run2(1);
|
|
2730
|
+
});
|
|
2731
|
+
Task2.race = (tasks) => {
|
|
2732
|
+
if (tasks.length === 0) {
|
|
2733
|
+
return () => Deferred.from.Promise(new Promise(() => {
|
|
2734
|
+
}));
|
|
2735
|
+
}
|
|
2736
|
+
return fromPromise((outerSignal) => {
|
|
2737
|
+
const controllers = tasks.map(() => new AbortController());
|
|
2738
|
+
const onOuterAbort = () => {
|
|
2739
|
+
for (const ctrl of controllers) {
|
|
2740
|
+
ctrl.abort();
|
|
2741
|
+
}
|
|
2742
|
+
};
|
|
2743
|
+
if (outerSignal) {
|
|
2744
|
+
if (outerSignal.aborted) {
|
|
2745
|
+
onOuterAbort();
|
|
2746
|
+
} else {
|
|
2747
|
+
outerSignal.addEventListener("abort", onOuterAbort, { once: true });
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
const promises = tasks.map((task, idx) => {
|
|
2751
|
+
const ctrl = controllers[idx];
|
|
2752
|
+
return toPromise(task, ctrl.signal).then((result) => {
|
|
2753
|
+
for (let i = 0; i < controllers.length; i++) {
|
|
2754
|
+
if (i !== idx) {
|
|
2755
|
+
controllers[i].abort();
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
outerSignal?.removeEventListener("abort", onOuterAbort);
|
|
2759
|
+
return result;
|
|
2760
|
+
});
|
|
2761
|
+
});
|
|
2762
|
+
return Promise.race(promises);
|
|
2763
|
+
});
|
|
2764
|
+
};
|
|
2765
|
+
Task2.sequence = (tasks) => fromPromise((signal) => Promise.all(tasks.map((t) => toPromise(t, signal))));
|
|
2766
|
+
Task2.sequential = (tasks) => fromPromise(async (signal) => {
|
|
2767
|
+
const results = [];
|
|
2768
|
+
for (const task of tasks) {
|
|
2769
|
+
if (signal?.aborted) {
|
|
2770
|
+
break;
|
|
2771
|
+
}
|
|
2772
|
+
results.push(await toPromise(task, signal));
|
|
2773
|
+
}
|
|
2774
|
+
return results;
|
|
2775
|
+
});
|
|
2776
|
+
Task2.timeout = (options) => (task) => fromPromise((outerSignal) => {
|
|
2777
|
+
const { duration, onTimeout } = options;
|
|
2778
|
+
const controller = new AbortController();
|
|
2779
|
+
let timerId;
|
|
2780
|
+
let cleanUp = () => {
|
|
2781
|
+
};
|
|
2782
|
+
const onOuterAbort = () => {
|
|
2783
|
+
cleanUp();
|
|
2784
|
+
controller.abort();
|
|
2785
|
+
};
|
|
2786
|
+
cleanUp = () => {
|
|
2787
|
+
clearTimeout(timerId);
|
|
2788
|
+
outerSignal?.removeEventListener("abort", onOuterAbort);
|
|
2789
|
+
};
|
|
2790
|
+
if (outerSignal) {
|
|
2791
|
+
if (outerSignal.aborted) {
|
|
2792
|
+
controller.abort();
|
|
2793
|
+
} else {
|
|
2794
|
+
outerSignal.addEventListener("abort", onOuterAbort, { once: true });
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
return Promise.race([
|
|
2798
|
+
toPromise(task, controller.signal).then((a) => {
|
|
2799
|
+
cleanUp();
|
|
2800
|
+
return Result.make.ok(a);
|
|
2801
|
+
}),
|
|
2802
|
+
new Promise((res) => {
|
|
2803
|
+
timerId = setTimeout(() => {
|
|
2804
|
+
controller.abort();
|
|
2805
|
+
cleanUp();
|
|
2806
|
+
res(Result.make.err(onTimeout()));
|
|
2807
|
+
}, getMs2(duration));
|
|
2808
|
+
})
|
|
2809
|
+
]);
|
|
2810
|
+
});
|
|
2811
|
+
Task2.abortable = (factory) => {
|
|
2812
|
+
let currentController = null;
|
|
2813
|
+
const abort = () => currentController?.abort();
|
|
2814
|
+
const task = (outerSignal) => {
|
|
2815
|
+
currentController?.abort();
|
|
2816
|
+
currentController = new AbortController();
|
|
2817
|
+
const controller = currentController;
|
|
2818
|
+
if (outerSignal) {
|
|
2819
|
+
if (outerSignal.aborted) {
|
|
2820
|
+
controller.abort(outerSignal.reason);
|
|
2821
|
+
} else {
|
|
2822
|
+
outerSignal.addEventListener("abort", () => controller.abort(outerSignal.reason), { once: true });
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
return Deferred.from.Promise(factory(controller.signal));
|
|
2826
|
+
};
|
|
2827
|
+
return { task, abort };
|
|
2828
|
+
};
|
|
2829
|
+
Task2.run = (signal) => (task) => task(signal);
|
|
2830
|
+
Task2.bindTo = (key) => (data) => (0, Task2.map)((a) => ({ [key]: a }))(data);
|
|
2831
|
+
Task2.bind = (key, f) => (data) => (0, Task2.chain)(
|
|
2832
|
+
(a) => (0, Task2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
2833
|
+
)(data);
|
|
2834
|
+
Task2.memoize = (task) => {
|
|
2835
|
+
let cached = null;
|
|
2836
|
+
return (signal) => {
|
|
2837
|
+
if (cached === null) {
|
|
2838
|
+
cached = task(signal);
|
|
2839
|
+
}
|
|
2840
|
+
return cached;
|
|
2841
|
+
};
|
|
2842
|
+
};
|
|
2843
|
+
Task2.withProgress = (onProgress) => (task) => (signal) => {
|
|
2844
|
+
onProgress(0);
|
|
2845
|
+
const d = task(signal);
|
|
2846
|
+
return Deferred.from.Promise(
|
|
2847
|
+
Deferred.to.Promise(d).then((res) => {
|
|
2848
|
+
onProgress(1);
|
|
2849
|
+
return res;
|
|
2850
|
+
})
|
|
2851
|
+
);
|
|
2852
|
+
};
|
|
2853
|
+
Task2.withLabel = (label) => (task) => {
|
|
2854
|
+
const fn = ((signal) => task(signal));
|
|
2855
|
+
Object.defineProperty(fn, "label", { value: label, writable: false, enumerable: true, configurable: true });
|
|
2856
|
+
return fn;
|
|
2857
|
+
};
|
|
2858
|
+
Task2.Maybe = TaskMaybe;
|
|
2859
|
+
Task2.Result = TaskResult;
|
|
2860
|
+
Task2.Validation = TaskValidation;
|
|
2861
|
+
})(Task || (Task = {}));
|
|
2862
|
+
|
|
2863
|
+
// src/Core/These.ts
|
|
2864
|
+
var These;
|
|
2865
|
+
((These2) => {
|
|
2866
|
+
let make;
|
|
2867
|
+
((make2) => {
|
|
2868
|
+
make2.first = (value) => ({ kind: "First", first: value });
|
|
2869
|
+
make2.second = (value) => ({ kind: "Second", second: value });
|
|
2870
|
+
make2.both = (f, s) => ({ kind: "Both", first: f, second: s });
|
|
2871
|
+
})(make = These2.make || (These2.make = {}));
|
|
2872
|
+
let is;
|
|
2873
|
+
((is2) => {
|
|
2874
|
+
is2.first = (data) => data.kind === "First";
|
|
2875
|
+
is2.second = (data) => data.kind === "Second";
|
|
2876
|
+
is2.both = (data) => data.kind === "Both";
|
|
2877
|
+
})(is = These2.is || (These2.is = {}));
|
|
2878
|
+
These2.hasFirst = (data) => data.kind === "First" || data.kind === "Both";
|
|
2879
|
+
These2.hasSecond = (data) => data.kind === "Second" || data.kind === "Both";
|
|
2880
|
+
These2.mapFirst = (f) => (data) => {
|
|
2881
|
+
if (is.second(data)) {
|
|
2882
|
+
return data;
|
|
2883
|
+
}
|
|
2884
|
+
if (is.first(data)) {
|
|
2885
|
+
return make.first(f(data.first));
|
|
2886
|
+
}
|
|
2887
|
+
return make.both(f(data.first), data.second);
|
|
2888
|
+
};
|
|
2889
|
+
These2.mapSecond = (f) => (data) => {
|
|
2890
|
+
if (is.first(data)) {
|
|
2891
|
+
return data;
|
|
2892
|
+
}
|
|
2893
|
+
if (is.second(data)) {
|
|
2894
|
+
return make.second(f(data.second));
|
|
2895
|
+
}
|
|
2896
|
+
return make.both(data.first, f(data.second));
|
|
2897
|
+
};
|
|
2898
|
+
These2.mapBoth = (onFirst, onSecond) => (data) => {
|
|
2899
|
+
if (is.second(data)) {
|
|
2900
|
+
return make.second(onSecond(data.second));
|
|
2901
|
+
}
|
|
2902
|
+
if (is.first(data)) {
|
|
2903
|
+
return make.first(onFirst(data.first));
|
|
2904
|
+
}
|
|
2905
|
+
return make.both(onFirst(data.first), onSecond(data.second));
|
|
2906
|
+
};
|
|
2907
|
+
These2.chainFirst = (f) => (data) => {
|
|
2908
|
+
if (is.second(data)) {
|
|
2909
|
+
return data;
|
|
2910
|
+
}
|
|
2911
|
+
return f(data.first);
|
|
2912
|
+
};
|
|
2913
|
+
These2.chainSecond = (f) => (data) => {
|
|
2914
|
+
if (is.first(data)) {
|
|
2915
|
+
return data;
|
|
2916
|
+
}
|
|
2917
|
+
return f(data.second);
|
|
2918
|
+
};
|
|
2919
|
+
These2.fold = (onFirst, onSecond, onBoth) => (data) => {
|
|
2920
|
+
if (is.second(data)) {
|
|
2921
|
+
return onSecond(data.second);
|
|
2922
|
+
}
|
|
2923
|
+
if (is.first(data)) {
|
|
2924
|
+
return onFirst(data.first);
|
|
2925
|
+
}
|
|
2926
|
+
return onBoth(data.first, data.second);
|
|
2927
|
+
};
|
|
2928
|
+
These2.match = (cases) => (data) => {
|
|
2929
|
+
if (is.second(data)) {
|
|
2930
|
+
return cases.second(data.second);
|
|
2931
|
+
}
|
|
2932
|
+
if (is.first(data)) {
|
|
2933
|
+
return cases.first(data.first);
|
|
2934
|
+
}
|
|
2935
|
+
return cases.both(data.first, data.second);
|
|
2936
|
+
};
|
|
2937
|
+
These2.getFirstOrElse = (defaultValue) => (data) => (0, These2.hasFirst)(data) ? data.first : defaultValue();
|
|
2938
|
+
These2.getSecondOrElse = (defaultValue) => (data) => (0, These2.hasSecond)(data) ? data.second : defaultValue();
|
|
2939
|
+
These2.tap = (f) => (data) => {
|
|
2940
|
+
if ((0, These2.hasFirst)(data)) {
|
|
2941
|
+
f(data.first);
|
|
2942
|
+
}
|
|
2943
|
+
return data;
|
|
2944
|
+
};
|
|
2945
|
+
These2.swap = (data) => {
|
|
2946
|
+
if (is.second(data)) {
|
|
2947
|
+
return make.first(data.second);
|
|
2948
|
+
}
|
|
2949
|
+
if (is.first(data)) {
|
|
2950
|
+
return make.second(data.first);
|
|
2951
|
+
}
|
|
2952
|
+
return make.both(data.second, data.first);
|
|
2953
|
+
};
|
|
2954
|
+
})(These || (These = {}));
|
|
2955
|
+
|
|
2956
|
+
// src/Core/Validation.ts
|
|
2957
|
+
var Validation;
|
|
2958
|
+
((Validation2) => {
|
|
2959
|
+
let make;
|
|
2960
|
+
((make2) => {
|
|
2961
|
+
make2.passed = (value) => ({ kind: "Passed", value });
|
|
2962
|
+
make2.failed = (error) => ({ kind: "Failed", errors: [error] });
|
|
2963
|
+
make2.failedAll = (errors) => ({ kind: "Failed", errors });
|
|
2964
|
+
})(make = Validation2.make || (Validation2.make = {}));
|
|
2965
|
+
let is;
|
|
2966
|
+
((is2) => {
|
|
2967
|
+
is2.passed = (data) => data.kind === "Passed";
|
|
2968
|
+
is2.failed = (data) => data.kind === "Failed";
|
|
2969
|
+
})(is = Validation2.is || (Validation2.is = {}));
|
|
2970
|
+
Validation2.tryCatch = (f, options) => {
|
|
2971
|
+
try {
|
|
2972
|
+
return make.passed(f());
|
|
2973
|
+
} catch (error) {
|
|
2974
|
+
return make.failed(options.onError(error));
|
|
2975
|
+
}
|
|
2976
|
+
};
|
|
2977
|
+
let from;
|
|
2978
|
+
((from2) => {
|
|
2979
|
+
from2.Predicate = (pred, onFalse) => (a) => pred(a) ? make.passed(a) : make.failed(onFalse(a));
|
|
2980
|
+
from2.nullable = (onNull) => (value) => value === null || value === void 0 ? make.failed(onNull()) : make.passed(value);
|
|
2981
|
+
from2.Maybe = (onNone) => (maybe) => Maybe.is.none(maybe) ? make.failed(onNone()) : make.passed(maybe.value);
|
|
2982
|
+
from2.Result = (data) => data.kind === "Ok" ? make.passed(data.value) : make.failed(data.error);
|
|
2983
|
+
})(from = Validation2.from || (Validation2.from = {}));
|
|
2984
|
+
Validation2.map = (f) => (data) => is.passed(data) ? make.passed(f(data.value)) : data;
|
|
2985
|
+
Validation2.mapError = (f) => (data) => is.failed(data) ? make.failedAll(data.errors.map(f)) : data;
|
|
2986
|
+
Validation2.ap = (arg) => (data) => {
|
|
2987
|
+
if (is.passed(data)) {
|
|
2988
|
+
return is.passed(arg) ? make.passed(data.value(arg.value)) : make.failedAll(arg.errors);
|
|
2989
|
+
}
|
|
2990
|
+
return is.passed(arg) ? make.failedAll(data.errors) : make.failedAll([...data.errors, ...arg.errors]);
|
|
2991
|
+
};
|
|
2992
|
+
Validation2.apCustom = (concat) => (arg) => (data) => {
|
|
2993
|
+
if (is.passed(data)) {
|
|
2994
|
+
return is.passed(arg) ? make.passed(data.value(arg.value)) : make.failedAll(arg.errors);
|
|
2995
|
+
}
|
|
2996
|
+
return is.passed(arg) ? make.failedAll(data.errors) : make.failedAll(concat(data.errors, arg.errors));
|
|
2997
|
+
};
|
|
2998
|
+
Validation2.fold = (onFailed, onPassed) => (data) => is.passed(data) ? onPassed(data.value) : onFailed(data.errors);
|
|
2999
|
+
Validation2.match = (cases) => (data) => is.passed(data) ? cases.passed(data.value) : cases.failed(data.errors);
|
|
3000
|
+
Validation2.getOrElse = (defaultValue) => (data) => is.passed(data) ? data.value : defaultValue();
|
|
3001
|
+
Validation2.tap = (f) => (data) => {
|
|
3002
|
+
if (is.passed(data)) {
|
|
3003
|
+
f(data.value);
|
|
3004
|
+
}
|
|
3005
|
+
return data;
|
|
3006
|
+
};
|
|
3007
|
+
Validation2.tapError = (f) => (data) => {
|
|
3008
|
+
if (is.failed(data)) {
|
|
3009
|
+
f(data.errors);
|
|
3010
|
+
}
|
|
3011
|
+
return data;
|
|
3012
|
+
};
|
|
3013
|
+
Validation2.recover = (fallback) => (data) => is.passed(data) ? data : fallback(data.errors);
|
|
3014
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => is.failed(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
3015
|
+
let to;
|
|
3016
|
+
((to2) => {
|
|
3017
|
+
function Result4(arg) {
|
|
3018
|
+
if (typeof arg === "function") {
|
|
3019
|
+
const combine = arg;
|
|
3020
|
+
return (val) => is.passed(val) ? Result.make.ok(val.value) : Result.make.err(combine(val.errors));
|
|
3021
|
+
}
|
|
3022
|
+
return is.passed(arg) ? Result.make.ok(arg.value) : Result.make.err(arg.errors);
|
|
3023
|
+
}
|
|
3024
|
+
to2.Result = Result4;
|
|
3025
|
+
to2.Maybe = (data) => is.passed(data) ? Maybe.make.some(data.value) : Maybe.make.none();
|
|
3026
|
+
})(to = Validation2.to || (Validation2.to = {}));
|
|
3027
|
+
Validation2.product = (first, second) => {
|
|
3028
|
+
if (is.passed(first)) {
|
|
3029
|
+
return is.passed(second) ? make.passed([first.value, second.value]) : make.failedAll(second.errors);
|
|
3030
|
+
}
|
|
3031
|
+
return is.passed(second) ? make.failedAll(first.errors) : make.failedAll([...first.errors, ...second.errors]);
|
|
3032
|
+
};
|
|
3033
|
+
Validation2.productAll = (data) => {
|
|
3034
|
+
const values = [];
|
|
3035
|
+
const errors = [];
|
|
3036
|
+
for (const v of data) {
|
|
3037
|
+
if (is.passed(v)) {
|
|
3038
|
+
values.push(v.value);
|
|
3039
|
+
} else {
|
|
3040
|
+
errors.push(...v.errors);
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
return isNonEmptyArr(errors) ? make.failedAll(errors) : make.passed(values);
|
|
3044
|
+
};
|
|
3045
|
+
Validation2.struct = (fields) => {
|
|
3046
|
+
const record = {};
|
|
3047
|
+
const errors = [];
|
|
3048
|
+
for (const key in fields) {
|
|
3049
|
+
if (Object.hasOwn(fields, key)) {
|
|
3050
|
+
const val = fields[key];
|
|
3051
|
+
if (is.passed(val)) {
|
|
3052
|
+
record[key] = val.value;
|
|
3053
|
+
} else {
|
|
3054
|
+
errors.push(...val.errors);
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
return isNonEmptyArr(errors) ? make.failedAll(errors) : make.passed(record);
|
|
3059
|
+
};
|
|
3060
|
+
})(Validation || (Validation = {}));
|
|
3061
|
+
|
|
3062
|
+
// src/Data/Arr.ts
|
|
3063
|
+
var ArrMaybe;
|
|
3064
|
+
((ArrMaybe2) => {
|
|
3065
|
+
ArrMaybe2.traverse = (f) => (data) => {
|
|
3066
|
+
const n = data.length;
|
|
3067
|
+
const result = new Array(n);
|
|
3068
|
+
for (let i = 0; i < n; i++) {
|
|
3069
|
+
const mapped = f(data[i]);
|
|
3070
|
+
if (mapped.kind === "None") {
|
|
3071
|
+
return Maybe.make.none();
|
|
3072
|
+
}
|
|
3073
|
+
result[i] = mapped.value;
|
|
3074
|
+
}
|
|
3075
|
+
return Maybe.make.some(result);
|
|
3076
|
+
};
|
|
3077
|
+
ArrMaybe2.sequence = (data) => (0, ArrMaybe2.traverse)((a) => a)(data);
|
|
3078
|
+
})(ArrMaybe || (ArrMaybe = {}));
|
|
3079
|
+
var ArrResult;
|
|
3080
|
+
((ArrResult2) => {
|
|
3081
|
+
ArrResult2.traverse = (f) => (data) => {
|
|
3082
|
+
const n = data.length;
|
|
3083
|
+
const result = new Array(n);
|
|
3084
|
+
for (let i = 0; i < n; i++) {
|
|
3085
|
+
const mapped = f(data[i]);
|
|
3086
|
+
if (mapped.kind === "Err") {
|
|
3087
|
+
return mapped;
|
|
3088
|
+
}
|
|
3089
|
+
result[i] = mapped.value;
|
|
3090
|
+
}
|
|
3091
|
+
return Result.make.ok(result);
|
|
3092
|
+
};
|
|
3093
|
+
ArrResult2.sequence = (data) => (0, ArrResult2.traverse)((a) => a)(data);
|
|
3094
|
+
})(ArrResult || (ArrResult = {}));
|
|
3095
|
+
var ArrTaskResult;
|
|
3096
|
+
((ArrTaskResult2) => {
|
|
3097
|
+
ArrTaskResult2.traverse = (f) => (data) => () => Deferred.from.Promise((async () => {
|
|
3098
|
+
const result = [];
|
|
3099
|
+
for (const a of data) {
|
|
3100
|
+
const r = await Deferred.to.Promise(f(a)());
|
|
3101
|
+
if (Result.is.err(r)) {
|
|
3102
|
+
return r;
|
|
3103
|
+
}
|
|
3104
|
+
result.push(r.value);
|
|
3105
|
+
}
|
|
3106
|
+
return Result.make.ok(result);
|
|
3107
|
+
})());
|
|
3108
|
+
ArrTaskResult2.sequence = (data) => (0, ArrTaskResult2.traverse)((a) => a)(data);
|
|
3109
|
+
})(ArrTaskResult || (ArrTaskResult = {}));
|
|
3110
|
+
var ArrTask;
|
|
3111
|
+
((ArrTask2) => {
|
|
3112
|
+
ArrTask2.traverse = (f) => (data) => () => Deferred.from.Promise(Promise.all(data.map((a) => Deferred.to.Promise(f(a)()))));
|
|
3113
|
+
ArrTask2.sequence = (data) => (0, ArrTask2.traverse)((a) => a)(data);
|
|
3114
|
+
ArrTask2.Result = ArrTaskResult;
|
|
3115
|
+
})(ArrTask || (ArrTask = {}));
|
|
3116
|
+
var ArrNonEmpty;
|
|
3117
|
+
((ArrNonEmpty2) => {
|
|
3118
|
+
ArrNonEmpty2.singleton = (value) => [value];
|
|
3119
|
+
let from;
|
|
3120
|
+
((from2) => {
|
|
3121
|
+
from2.Array = (data) => isNonEmptyArr(data) ? Maybe.make.some(data) : Maybe.make.none();
|
|
3122
|
+
})(from = ArrNonEmpty2.from || (ArrNonEmpty2.from = {}));
|
|
3123
|
+
ArrNonEmpty2.head = (data) => data[0];
|
|
3124
|
+
ArrNonEmpty2.last = (data) => data[data.length - 1];
|
|
3125
|
+
ArrNonEmpty2.tail = (data) => data.slice(1);
|
|
3126
|
+
ArrNonEmpty2.reduce = (f) => (data) => data.reduce(f);
|
|
3127
|
+
ArrNonEmpty2.map = (f) => (data) => Arr.map(f)(data);
|
|
3128
|
+
ArrNonEmpty2.mapWithIndex = (f) => (data) => Arr.mapWithIndex(f)(data);
|
|
3129
|
+
ArrNonEmpty2.intersperse = (sep) => (data) => Arr.intersperse(sep)(data);
|
|
3130
|
+
ArrNonEmpty2.concat = (other) => (data) => Arr.concat(other)(data);
|
|
3131
|
+
ArrNonEmpty2.reverse = (data) => Arr.reverse(data);
|
|
3132
|
+
})(ArrNonEmpty || (ArrNonEmpty = {}));
|
|
3133
|
+
var Arr;
|
|
3134
|
+
((Arr2) => {
|
|
3135
|
+
Arr2.head = (data) => data.length > 0 ? Maybe.make.some(data[0]) : Maybe.make.none();
|
|
3136
|
+
Arr2.last = (data) => data.length > 0 ? Maybe.make.some(data[data.length - 1]) : Maybe.make.none();
|
|
3137
|
+
Arr2.tail = (data) => data.length > 0 ? Maybe.make.some(data.slice(1)) : Maybe.make.none();
|
|
3138
|
+
Arr2.init = (data) => data.length > 0 ? Maybe.make.some(data.slice(0, -1)) : Maybe.make.none();
|
|
3139
|
+
Arr2.findFirst = (predicate) => (data) => {
|
|
3140
|
+
const idx = data.findIndex(predicate);
|
|
3141
|
+
return idx !== -1 ? Maybe.make.some(data[idx]) : Maybe.make.none();
|
|
3142
|
+
};
|
|
3143
|
+
Arr2.findLast = (predicate) => (data) => {
|
|
3144
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
3145
|
+
if (predicate(data[i])) {
|
|
3146
|
+
return Maybe.make.some(data[i]);
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
return Maybe.make.none();
|
|
3150
|
+
};
|
|
3151
|
+
Arr2.findIndex = (predicate) => (data) => {
|
|
3152
|
+
const idx = data.findIndex(predicate);
|
|
3153
|
+
return idx !== -1 ? Maybe.make.some(idx) : Maybe.make.none();
|
|
3154
|
+
};
|
|
3155
|
+
Arr2.map = (f) => (data) => {
|
|
3156
|
+
const n = data.length;
|
|
3157
|
+
const result = new Array(n);
|
|
3158
|
+
for (let i = 0; i < n; i++) {
|
|
3159
|
+
result[i] = f(data[i]);
|
|
3160
|
+
}
|
|
3161
|
+
return result;
|
|
3162
|
+
};
|
|
3163
|
+
Arr2.mapWithIndex = (f) => (data) => {
|
|
3164
|
+
const n = data.length;
|
|
3165
|
+
const result = new Array(n);
|
|
3166
|
+
for (let i = 0; i < n; i++) {
|
|
3167
|
+
result[i] = f(i, data[i]);
|
|
3168
|
+
}
|
|
3169
|
+
return result;
|
|
3170
|
+
};
|
|
3171
|
+
Arr2.filter = (predicate) => (data) => {
|
|
3172
|
+
const n = data.length;
|
|
3173
|
+
const result = [];
|
|
3174
|
+
for (let i = 0; i < n; i++) {
|
|
3175
|
+
if (predicate(data[i])) {
|
|
3176
|
+
result.push(data[i]);
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
return result;
|
|
3180
|
+
};
|
|
3181
|
+
Arr2.filterMap = (f) => (data) => {
|
|
3182
|
+
const result = [];
|
|
3183
|
+
for (let i = 0; i < data.length; i++) {
|
|
3184
|
+
const mapped = f(data[i]);
|
|
3185
|
+
if (mapped.kind === "Some") {
|
|
3186
|
+
result.push(mapped.value);
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
return result;
|
|
3190
|
+
};
|
|
3191
|
+
Arr2.partition = (predicate) => (data) => {
|
|
3192
|
+
const pass = [];
|
|
3193
|
+
const fail = [];
|
|
3194
|
+
for (const a of data) {
|
|
3195
|
+
(predicate(a) ? pass : fail).push(a);
|
|
3196
|
+
}
|
|
3197
|
+
return [pass, fail];
|
|
3198
|
+
};
|
|
3199
|
+
Arr2.compact = (data) => {
|
|
3200
|
+
const result = [];
|
|
3201
|
+
for (const item of data) {
|
|
3202
|
+
if (item.kind === "Some") {
|
|
3203
|
+
result.push(item.value);
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3206
|
+
return result;
|
|
3207
|
+
};
|
|
3208
|
+
Arr2.separate = (data) => {
|
|
3209
|
+
const errors = [];
|
|
3210
|
+
const successes = [];
|
|
3211
|
+
for (const item of data) {
|
|
3212
|
+
if (item.kind === "Ok") {
|
|
3213
|
+
successes.push(item.value);
|
|
3214
|
+
} else {
|
|
3215
|
+
errors.push(item.error);
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
return [errors, successes];
|
|
3219
|
+
};
|
|
3220
|
+
Arr2.partitionMap = (f) => (data) => {
|
|
3221
|
+
const errors = [];
|
|
3222
|
+
const successes = [];
|
|
3223
|
+
for (const item of data) {
|
|
3224
|
+
const mapped = f(item);
|
|
3225
|
+
if (mapped.kind === "Ok") {
|
|
3226
|
+
successes.push(mapped.value);
|
|
3227
|
+
} else {
|
|
3228
|
+
errors.push(mapped.error);
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
return [errors, successes];
|
|
3232
|
+
};
|
|
3233
|
+
Arr2.groupBy = (f) => (data) => {
|
|
3234
|
+
const result = {};
|
|
3235
|
+
for (const a of data) {
|
|
3236
|
+
const key = f(a);
|
|
3237
|
+
if (!result[key]) {
|
|
3238
|
+
result[key] = [];
|
|
3239
|
+
}
|
|
3240
|
+
result[key].push(a);
|
|
3241
|
+
}
|
|
3242
|
+
return result;
|
|
3243
|
+
};
|
|
3244
|
+
Arr2.uniq = (data) => [...new Set(data)];
|
|
3245
|
+
Arr2.uniqBy = (f) => (data) => {
|
|
3246
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3247
|
+
const result = [];
|
|
3248
|
+
for (const a of data) {
|
|
3249
|
+
const key = f(a);
|
|
3250
|
+
if (!seen.has(key)) {
|
|
3251
|
+
seen.add(key);
|
|
3252
|
+
result.push(a);
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
return result;
|
|
3256
|
+
};
|
|
3257
|
+
Arr2.uniqWith = (eq) => (data) => {
|
|
3258
|
+
const result = [];
|
|
3259
|
+
for (const a of data) {
|
|
3260
|
+
if (!result.some((x) => eq(x, a))) {
|
|
3261
|
+
result.push(a);
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
return result;
|
|
3265
|
+
};
|
|
3266
|
+
Arr2.sortBy = (compare) => (data) => {
|
|
3267
|
+
const arr = data;
|
|
3268
|
+
if (typeof arr.toSorted === "function") {
|
|
3269
|
+
return arr.toSorted(compare);
|
|
3270
|
+
}
|
|
3271
|
+
return [...data].toSorted(compare);
|
|
3272
|
+
};
|
|
3273
|
+
Arr2.sortWith = (ord) => (data) => {
|
|
3274
|
+
const arr = data;
|
|
3275
|
+
if (typeof arr.toSorted === "function") {
|
|
3276
|
+
return arr.toSorted(ord);
|
|
3277
|
+
}
|
|
3278
|
+
return [...data].sort(ord);
|
|
3279
|
+
};
|
|
3280
|
+
Arr2.zip = (other) => (data) => {
|
|
3281
|
+
const len = Math.min(data.length, other.length);
|
|
3282
|
+
const result = new Array(len);
|
|
3283
|
+
for (let i = 0; i < len; i++) {
|
|
3284
|
+
result[i] = [data[i], other[i]];
|
|
3285
|
+
}
|
|
3286
|
+
return result;
|
|
3287
|
+
};
|
|
3288
|
+
Arr2.zipWith = (f) => (other) => (data) => {
|
|
3289
|
+
const len = Math.min(data.length, other.length);
|
|
3290
|
+
const result = new Array(len);
|
|
3291
|
+
for (let i = 0; i < len; i++) {
|
|
3292
|
+
result[i] = f(data[i], other[i]);
|
|
3293
|
+
}
|
|
3294
|
+
return result;
|
|
3295
|
+
};
|
|
3296
|
+
Arr2.intersperse = (sep) => (data) => {
|
|
3297
|
+
if (data.length <= 1) {
|
|
3298
|
+
return data;
|
|
3299
|
+
}
|
|
3300
|
+
const result = [data[0]];
|
|
3301
|
+
for (let i = 1; i < data.length; i++) {
|
|
3302
|
+
result.push(sep, data[i]);
|
|
3303
|
+
}
|
|
3304
|
+
return result;
|
|
3305
|
+
};
|
|
3306
|
+
Arr2.concat = (other) => (data) => [...data, ...other];
|
|
3307
|
+
Arr2.chunksOf = (n) => (data) => {
|
|
3308
|
+
if (n <= 0) {
|
|
3309
|
+
return [];
|
|
3310
|
+
}
|
|
3311
|
+
const result = [];
|
|
3312
|
+
for (let i = 0; i < data.length; i += n) {
|
|
3313
|
+
result.push(data.slice(i, i + n));
|
|
3314
|
+
}
|
|
3315
|
+
return result;
|
|
3316
|
+
};
|
|
3317
|
+
Arr2.flatten = (data) => {
|
|
3318
|
+
let totalLen = 0;
|
|
3319
|
+
const outerLen = data.length;
|
|
3320
|
+
for (let i = 0; i < outerLen; i++) {
|
|
3321
|
+
totalLen += data[i].length;
|
|
3322
|
+
}
|
|
3323
|
+
const result = new Array(totalLen);
|
|
3324
|
+
let idx = 0;
|
|
3325
|
+
for (let i = 0; i < outerLen; i++) {
|
|
3326
|
+
const chunk = data[i];
|
|
3327
|
+
const innerLen = chunk.length;
|
|
3328
|
+
for (let j = 0; j < innerLen; j++) {
|
|
3329
|
+
result[idx++] = chunk[j];
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
return result;
|
|
3333
|
+
};
|
|
3334
|
+
Arr2.flatMap = (f) => (data) => {
|
|
3335
|
+
const n = data.length;
|
|
3336
|
+
const result = [];
|
|
3337
|
+
for (let i = 0; i < n; i++) {
|
|
3338
|
+
const chunk = f(data[i]);
|
|
3339
|
+
const m = chunk.length;
|
|
3340
|
+
for (let j = 0; j < m; j++) {
|
|
3341
|
+
result.push(chunk[j]);
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
return result;
|
|
3345
|
+
};
|
|
3346
|
+
Arr2.reduce = (initial, f) => (data) => data.reduce(f, initial);
|
|
3347
|
+
const _traverseTask = Object.assign((f) => ArrTask.traverse(f), {
|
|
3348
|
+
Result: ArrTaskResult.traverse
|
|
3349
|
+
});
|
|
3350
|
+
const _sequenceTask = Object.assign((data) => ArrTask.sequence(data), {
|
|
3351
|
+
Result: ArrTaskResult.sequence
|
|
3352
|
+
});
|
|
3353
|
+
let traverse;
|
|
3354
|
+
((traverse2) => {
|
|
3355
|
+
traverse2.Maybe = ArrMaybe.traverse;
|
|
3356
|
+
traverse2.Result = ArrResult.traverse;
|
|
3357
|
+
traverse2.Task = _traverseTask;
|
|
3358
|
+
})(traverse = Arr2.traverse || (Arr2.traverse = {}));
|
|
3359
|
+
let sequence;
|
|
3360
|
+
((sequence2) => {
|
|
3361
|
+
sequence2.Maybe = ArrMaybe.sequence;
|
|
3362
|
+
sequence2.Result = ArrResult.sequence;
|
|
3363
|
+
sequence2.Task = _sequenceTask;
|
|
3364
|
+
})(sequence = Arr2.sequence || (Arr2.sequence = {}));
|
|
3365
|
+
let is;
|
|
3366
|
+
((is2) => {
|
|
3367
|
+
is2.empty = (data) => data.length === 0;
|
|
3368
|
+
is2.nonEmpty = (data) => isNonEmptyArr(data);
|
|
3369
|
+
})(is = Arr2.is || (Arr2.is = {}));
|
|
3370
|
+
Arr2.prepend = (value) => (data) => [value, ...data];
|
|
3371
|
+
Arr2.append = (value) => (data) => [...data, value];
|
|
3372
|
+
Arr2.size = (data) => data.length;
|
|
3373
|
+
Arr2.some = (predicate) => (data) => {
|
|
3374
|
+
const n = data.length;
|
|
3375
|
+
for (let i = 0; i < n; i++) {
|
|
3376
|
+
if (predicate(data[i])) {
|
|
3377
|
+
return true;
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
return false;
|
|
3381
|
+
};
|
|
3382
|
+
Arr2.every = (predicate) => (data) => {
|
|
3383
|
+
const n = data.length;
|
|
3384
|
+
for (let i = 0; i < n; i++) {
|
|
3385
|
+
if (!predicate(data[i])) {
|
|
3386
|
+
return false;
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
return true;
|
|
3390
|
+
};
|
|
3391
|
+
Arr2.reverse = (data) => [...data].toReversed();
|
|
3392
|
+
Arr2.insertAt = (index, item) => (data) => {
|
|
3393
|
+
const i = Math.max(0, Math.min(index, data.length));
|
|
3394
|
+
const arr = data;
|
|
3395
|
+
if (typeof arr.toSpliced === "function") {
|
|
3396
|
+
return arr.toSpliced(i, 0, item);
|
|
3397
|
+
}
|
|
3398
|
+
const result = [...data];
|
|
3399
|
+
result.splice(i, 0, item);
|
|
3400
|
+
return result;
|
|
3401
|
+
};
|
|
3402
|
+
Arr2.removeAt = (index) => (data) => {
|
|
3403
|
+
if (index < 0 || index >= data.length) {
|
|
3404
|
+
return data;
|
|
3405
|
+
}
|
|
3406
|
+
const arr = data;
|
|
3407
|
+
if (typeof arr.toSpliced === "function") {
|
|
3408
|
+
return arr.toSpliced(index, 1);
|
|
3409
|
+
}
|
|
3410
|
+
const result = [...data];
|
|
3411
|
+
result.splice(index, 1);
|
|
3412
|
+
return result;
|
|
3413
|
+
};
|
|
3414
|
+
Arr2.take = (n) => (data) => n <= 0 ? [] : data.slice(0, n);
|
|
3415
|
+
Arr2.drop = (n) => (data) => data.slice(n);
|
|
3416
|
+
Arr2.takeWhile = (predicate) => (data) => {
|
|
3417
|
+
const result = [];
|
|
3418
|
+
for (const a of data) {
|
|
3419
|
+
if (!predicate(a)) {
|
|
3420
|
+
break;
|
|
3421
|
+
}
|
|
3422
|
+
result.push(a);
|
|
3423
|
+
}
|
|
3424
|
+
return result;
|
|
3425
|
+
};
|
|
3426
|
+
Arr2.dropWhile = (predicate) => (data) => {
|
|
3427
|
+
let i = 0;
|
|
3428
|
+
while (i < data.length && predicate(data[i])) {
|
|
3429
|
+
i++;
|
|
3430
|
+
}
|
|
3431
|
+
return data.slice(i);
|
|
3432
|
+
};
|
|
3433
|
+
Arr2.scan = (initial, f) => (data) => {
|
|
3434
|
+
const n = data.length;
|
|
3435
|
+
const result = new Array(n);
|
|
3436
|
+
let acc = initial;
|
|
3437
|
+
for (let i = 0; i < n; i++) {
|
|
3438
|
+
acc = f(acc, data[i]);
|
|
3439
|
+
result[i] = acc;
|
|
3440
|
+
}
|
|
3441
|
+
return result;
|
|
3442
|
+
};
|
|
3443
|
+
Arr2.splitAt = (index) => (data) => {
|
|
3444
|
+
const i = Math.max(0, index);
|
|
3445
|
+
return [data.slice(0, i), data.slice(i)];
|
|
3446
|
+
};
|
|
3447
|
+
Arr2.partitionMaybe = (f) => (data) => {
|
|
3448
|
+
const failures = [];
|
|
3449
|
+
const successes = [];
|
|
3450
|
+
for (let i = 0; i < data.length; i++) {
|
|
3451
|
+
const res = f(data[i]);
|
|
3452
|
+
if (res.kind === "Some") {
|
|
3453
|
+
successes.push(res.value);
|
|
3454
|
+
} else {
|
|
3455
|
+
failures.push(data[i]);
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
return [failures, successes];
|
|
3459
|
+
};
|
|
3460
|
+
Arr2.at = (index) => (data) => {
|
|
3461
|
+
const targetIndex = index < 0 ? data.length + index : index;
|
|
3462
|
+
if (targetIndex < 0 || targetIndex >= data.length) {
|
|
3463
|
+
return Maybe.make.none();
|
|
3464
|
+
}
|
|
3465
|
+
return Maybe.make.some(data[targetIndex]);
|
|
3466
|
+
};
|
|
3467
|
+
Arr2.findMap = (f) => (data) => {
|
|
3468
|
+
for (let i = 0; i < data.length; i++) {
|
|
3469
|
+
const res = f(data[i]);
|
|
3470
|
+
if (res.kind === "Some") {
|
|
3471
|
+
return res;
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
return Maybe.make.none();
|
|
3475
|
+
};
|
|
3476
|
+
Arr2.indexBy = (keyFn) => (data) => {
|
|
3477
|
+
const map2 = new globalThis.Map();
|
|
3478
|
+
for (let i = 0; i < data.length; i++) {
|
|
3479
|
+
map2.set(keyFn(data[i]), data[i]);
|
|
3480
|
+
}
|
|
3481
|
+
return map2;
|
|
3482
|
+
};
|
|
3483
|
+
Arr2.frequencies = (data) => {
|
|
3484
|
+
const map2 = new globalThis.Map();
|
|
3485
|
+
for (let i = 0; i < data.length; i++) {
|
|
3486
|
+
const item = data[i];
|
|
3487
|
+
map2.set(item, (map2.get(item) ?? 0) + 1);
|
|
3488
|
+
}
|
|
3489
|
+
return map2;
|
|
3490
|
+
};
|
|
3491
|
+
Arr2.chunkBy = (keyFn) => (data) => {
|
|
3492
|
+
if (data.length === 0) {
|
|
3493
|
+
return [];
|
|
3494
|
+
}
|
|
3495
|
+
const result = [];
|
|
3496
|
+
let currentChunk = [data[0]];
|
|
3497
|
+
let currentKey = keyFn(data[0]);
|
|
3498
|
+
for (let i = 1; i < data.length; i++) {
|
|
3499
|
+
const item = data[i];
|
|
3500
|
+
const key = keyFn(item);
|
|
3501
|
+
if (Object.is(key, currentKey)) {
|
|
3502
|
+
currentChunk.push(item);
|
|
3503
|
+
} else {
|
|
3504
|
+
result.push(currentChunk);
|
|
3505
|
+
currentChunk = [item];
|
|
3506
|
+
currentKey = key;
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
result.push(currentChunk);
|
|
3510
|
+
return result;
|
|
3511
|
+
};
|
|
3512
|
+
Arr2.dedupeAdjacent = (eq = (a, b) => Object.is(a, b)) => (data) => {
|
|
3513
|
+
if (data.length === 0) {
|
|
3514
|
+
return [];
|
|
3515
|
+
}
|
|
3516
|
+
const result = [data[0]];
|
|
3517
|
+
for (let i = 1; i < data.length; i++) {
|
|
3518
|
+
if (!eq(data[i], result[result.length - 1])) {
|
|
3519
|
+
result.push(data[i]);
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
return result;
|
|
3523
|
+
};
|
|
3524
|
+
Arr2.windowed = (size2, options) => (data) => {
|
|
3525
|
+
const step = options?.step ?? 1;
|
|
3526
|
+
if (size2 <= 0 || step <= 0 || data.length < size2) {
|
|
3527
|
+
return [];
|
|
3528
|
+
}
|
|
3529
|
+
const result = [];
|
|
3530
|
+
for (let i = 0; i <= data.length - size2; i += step) {
|
|
3531
|
+
result.push(data.slice(i, i + size2));
|
|
3532
|
+
}
|
|
3533
|
+
return result;
|
|
3534
|
+
};
|
|
3535
|
+
Arr2.unfold = (initial, f) => {
|
|
3536
|
+
const result = [];
|
|
3537
|
+
let currentState = initial;
|
|
3538
|
+
while (true) {
|
|
3539
|
+
const next = f(currentState);
|
|
3540
|
+
if (next.kind === "None") {
|
|
3541
|
+
break;
|
|
3542
|
+
}
|
|
3543
|
+
const [item, nextState] = next.value;
|
|
3544
|
+
result.push(item);
|
|
3545
|
+
currentState = nextState;
|
|
3546
|
+
}
|
|
3547
|
+
return result;
|
|
3548
|
+
};
|
|
3549
|
+
Arr2.NonEmpty = ArrNonEmpty;
|
|
3550
|
+
})(Arr || (Arr = {}));
|
|
3551
|
+
|
|
3552
|
+
// src/Data/BigNum.ts
|
|
3553
|
+
var BigNum;
|
|
3554
|
+
((BigNum2) => {
|
|
3555
|
+
let from;
|
|
3556
|
+
((from2) => {
|
|
3557
|
+
from2.string = (s) => {
|
|
3558
|
+
try {
|
|
3559
|
+
if (s.trim() === "") {
|
|
3560
|
+
return Maybe.make.none();
|
|
3561
|
+
}
|
|
3562
|
+
return Maybe.make.some(BigInt(s));
|
|
3563
|
+
} catch {
|
|
3564
|
+
return Maybe.make.none();
|
|
3565
|
+
}
|
|
3566
|
+
};
|
|
3567
|
+
from2.number = (n) => {
|
|
3568
|
+
if (!Number.isInteger(n) || n < Number.MIN_SAFE_INTEGER || n > Number.MAX_SAFE_INTEGER) {
|
|
3569
|
+
return Maybe.make.none();
|
|
3570
|
+
}
|
|
3571
|
+
return Maybe.make.some(BigInt(n));
|
|
3572
|
+
};
|
|
3573
|
+
})(from = BigNum2.from || (BigNum2.from = {}));
|
|
3574
|
+
let to;
|
|
3575
|
+
((to2) => {
|
|
3576
|
+
to2.number = (b) => {
|
|
3577
|
+
if (b < BigInt(Number.MIN_SAFE_INTEGER) || b > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
3578
|
+
return Maybe.make.none();
|
|
3579
|
+
}
|
|
3580
|
+
return Maybe.make.some(Number(b));
|
|
3581
|
+
};
|
|
3582
|
+
})(to = BigNum2.to || (BigNum2.to = {}));
|
|
3583
|
+
BigNum2.add = (b) => (a) => a + b;
|
|
3584
|
+
BigNum2.sub = (b) => (a) => a - b;
|
|
3585
|
+
BigNum2.mul = (b) => (a) => a * b;
|
|
3586
|
+
BigNum2.div = (b) => (a) => b === 0n ? Maybe.make.none() : Maybe.make.some(a / b);
|
|
3587
|
+
BigNum2.mod = (b) => (a) => b === 0n ? Maybe.make.none() : Maybe.make.some(a % b);
|
|
3588
|
+
BigNum2.clamp = (min2, max2) => (a) => a < min2 ? min2 : a > max2 ? max2 : a;
|
|
3589
|
+
BigNum2.inRange = (start, end) => (a) => a >= start && a < end;
|
|
3590
|
+
BigNum2.abs = (a) => a < 0n ? -a : a;
|
|
3591
|
+
BigNum2.min = (b) => (a) => a < b ? a : b;
|
|
3592
|
+
BigNum2.max = (b) => (a) => a > b ? a : b;
|
|
3593
|
+
})(BigNum || (BigNum = {}));
|
|
3594
|
+
|
|
3595
|
+
// src/Data/Dict.ts
|
|
3596
|
+
var DictNonEmpty;
|
|
3597
|
+
((DictNonEmpty2) => {
|
|
3598
|
+
DictNonEmpty2.singleton = (key, value) => new globalThis.Map([[key, value]]);
|
|
3599
|
+
let from;
|
|
3600
|
+
((from2) => {
|
|
3601
|
+
from2.Map = (m) => m.size > 0 ? Maybe.make.some(m) : Maybe.make.none();
|
|
3602
|
+
})(from = DictNonEmpty2.from || (DictNonEmpty2.from = {}));
|
|
3603
|
+
DictNonEmpty2.keys = (m) => Dict.keys(m);
|
|
3604
|
+
DictNonEmpty2.values = (m) => Dict.values(m);
|
|
3605
|
+
DictNonEmpty2.entries = (m) => Dict.entries(m);
|
|
3606
|
+
DictNonEmpty2.reduce = (f) => (m) => (0, DictNonEmpty2.values)(m).reduce(f);
|
|
3607
|
+
DictNonEmpty2.map = (f) => (m) => Dict.map(f)(m);
|
|
3608
|
+
DictNonEmpty2.mapWithKey = (f) => (m) => Dict.mapWithKey(f)(m);
|
|
3609
|
+
})(DictNonEmpty || (DictNonEmpty = {}));
|
|
3610
|
+
var Dict;
|
|
3611
|
+
((Dict2) => {
|
|
3612
|
+
let is;
|
|
3613
|
+
((is2) => {
|
|
3614
|
+
is2.empty = (m) => m.size === 0;
|
|
3615
|
+
is2.nonEmpty = (m) => m.size > 0;
|
|
3616
|
+
})(is = Dict2.is || (Dict2.is = {}));
|
|
3617
|
+
Dict2.empty = () => new globalThis.Map();
|
|
3618
|
+
Dict2.singleton = (key, value) => new globalThis.Map([[key, value]]);
|
|
3619
|
+
let from;
|
|
3620
|
+
((from2) => {
|
|
3621
|
+
from2.entries = (entries3) => new globalThis.Map(entries3);
|
|
3622
|
+
from2.Record = (rec) => new globalThis.Map(Object.entries(rec));
|
|
3623
|
+
})(from = Dict2.from || (Dict2.from = {}));
|
|
3624
|
+
Dict2.groupBy = (keyFn) => (items) => {
|
|
3625
|
+
const result = new globalThis.Map();
|
|
3626
|
+
for (const item of items) {
|
|
3627
|
+
const key = keyFn(item);
|
|
3628
|
+
const arr = result.get(key);
|
|
3629
|
+
if (arr !== void 0) {
|
|
3630
|
+
arr.push(item);
|
|
3631
|
+
} else {
|
|
3632
|
+
result.set(key, [item]);
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
return result;
|
|
3636
|
+
};
|
|
3637
|
+
Dict2.has = (key) => (m) => m.has(key);
|
|
3638
|
+
Dict2.lookup = (key) => (m) => m.has(key) ? Maybe.make.some(m.get(key)) : Maybe.make.none();
|
|
3639
|
+
Dict2.size = (m) => m.size;
|
|
3640
|
+
Dict2.keys = (m) => [...m.keys()];
|
|
3641
|
+
Dict2.values = (m) => [...m.values()];
|
|
3642
|
+
Dict2.entries = (m) => [...m.entries()];
|
|
3643
|
+
Dict2.insert = (key, value) => (m) => {
|
|
3644
|
+
const result = new globalThis.Map(m);
|
|
3645
|
+
result.set(key, value);
|
|
3646
|
+
return result;
|
|
3647
|
+
};
|
|
3648
|
+
Dict2.remove = (key) => (m) => {
|
|
3649
|
+
if (!m.has(key)) {
|
|
3650
|
+
return m;
|
|
3651
|
+
}
|
|
3652
|
+
const result = new globalThis.Map(m);
|
|
3653
|
+
result.delete(key);
|
|
3654
|
+
return result;
|
|
3655
|
+
};
|
|
3656
|
+
Dict2.upsert = (key, f) => (m) => {
|
|
3657
|
+
const result = new globalThis.Map(m);
|
|
3658
|
+
result.set(key, f((0, Dict2.lookup)(key)(m)));
|
|
3659
|
+
return result;
|
|
3660
|
+
};
|
|
3661
|
+
Dict2.map = (f) => (m) => {
|
|
3662
|
+
const result = new globalThis.Map();
|
|
3663
|
+
for (const [k, v] of m) {
|
|
3664
|
+
result.set(k, f(v));
|
|
3665
|
+
}
|
|
3666
|
+
return result;
|
|
3667
|
+
};
|
|
3668
|
+
Dict2.mapWithKey = (f) => (m) => {
|
|
3669
|
+
const result = new globalThis.Map();
|
|
3670
|
+
for (const [k, v] of m) {
|
|
3671
|
+
result.set(k, f(k, v));
|
|
3672
|
+
}
|
|
3673
|
+
return result;
|
|
3674
|
+
};
|
|
3675
|
+
Dict2.filter = (predicate) => (m) => {
|
|
3676
|
+
const result = new globalThis.Map();
|
|
3677
|
+
for (const [k, v] of m) {
|
|
3678
|
+
if (predicate(v)) {
|
|
3679
|
+
result.set(k, v);
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
return result;
|
|
3683
|
+
};
|
|
3684
|
+
Dict2.filterWithKey = (predicate) => (m) => {
|
|
3685
|
+
const result = new globalThis.Map();
|
|
3686
|
+
for (const [k, v] of m) {
|
|
3687
|
+
if (predicate(k, v)) {
|
|
3688
|
+
result.set(k, v);
|
|
3689
|
+
}
|
|
3690
|
+
}
|
|
3691
|
+
return result;
|
|
3692
|
+
};
|
|
3693
|
+
Dict2.compact = (m) => {
|
|
3694
|
+
const result = new globalThis.Map();
|
|
3695
|
+
for (const [k, v] of m) {
|
|
3696
|
+
if (v.kind === "Some") {
|
|
3697
|
+
result.set(k, v.value);
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
return result;
|
|
3701
|
+
};
|
|
3702
|
+
Dict2.filterMap = (f) => (m) => {
|
|
3703
|
+
const result = new globalThis.Map();
|
|
3704
|
+
for (const [key, value] of m) {
|
|
3705
|
+
const mapped = f(value);
|
|
3706
|
+
if (mapped.kind === "Some") {
|
|
3707
|
+
result.set(key, mapped.value);
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
return result;
|
|
3711
|
+
};
|
|
3712
|
+
Dict2.union = (other) => (m) => {
|
|
3713
|
+
const result = new globalThis.Map(m);
|
|
3714
|
+
for (const [k, v] of other) {
|
|
3715
|
+
result.set(k, v);
|
|
3716
|
+
}
|
|
3717
|
+
return result;
|
|
3718
|
+
};
|
|
3719
|
+
Dict2.intersection = (other) => (m) => {
|
|
3720
|
+
const result = new globalThis.Map();
|
|
3721
|
+
for (const [k, v] of m) {
|
|
3722
|
+
if (other.has(k)) {
|
|
3723
|
+
result.set(k, v);
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
return result;
|
|
3727
|
+
};
|
|
3728
|
+
Dict2.difference = (other) => (m) => {
|
|
3729
|
+
const result = new globalThis.Map();
|
|
3730
|
+
for (const [k, v] of m) {
|
|
3731
|
+
if (!other.has(k)) {
|
|
3732
|
+
result.set(k, v);
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
return result;
|
|
3736
|
+
};
|
|
3737
|
+
Dict2.reduce = (init, f) => (m) => {
|
|
3738
|
+
let acc = init;
|
|
3739
|
+
for (const v of m.values()) {
|
|
3740
|
+
acc = f(acc, v);
|
|
3741
|
+
}
|
|
3742
|
+
return acc;
|
|
3743
|
+
};
|
|
3744
|
+
Dict2.reduceWithKey = (init, f) => (m) => {
|
|
3745
|
+
let acc = init;
|
|
3746
|
+
for (const [k, v] of m) {
|
|
3747
|
+
acc = f(acc, v, k);
|
|
3748
|
+
}
|
|
3749
|
+
return acc;
|
|
3750
|
+
};
|
|
3751
|
+
function mergeWith(combine) {
|
|
3752
|
+
return (arg1, arg2) => {
|
|
3753
|
+
if (arg2 !== void 0) {
|
|
3754
|
+
const first = arg1;
|
|
3755
|
+
const second2 = arg2;
|
|
3756
|
+
const res = new globalThis.Map(first);
|
|
3757
|
+
for (const [k, v] of second2) {
|
|
3758
|
+
if (res.has(k)) {
|
|
3759
|
+
res.set(k, combine(res.get(k), v));
|
|
3760
|
+
} else {
|
|
3761
|
+
res.set(k, v);
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
return res;
|
|
3765
|
+
}
|
|
3766
|
+
const second = arg1;
|
|
3767
|
+
return (first) => {
|
|
3768
|
+
const res = new globalThis.Map(first);
|
|
3769
|
+
for (const [k, v] of second) {
|
|
3770
|
+
if (res.has(k)) {
|
|
3771
|
+
res.set(k, combine(res.get(k), v));
|
|
3772
|
+
} else {
|
|
3773
|
+
res.set(k, v);
|
|
3774
|
+
}
|
|
3775
|
+
}
|
|
3776
|
+
return res;
|
|
3777
|
+
};
|
|
3778
|
+
};
|
|
3779
|
+
}
|
|
3780
|
+
Dict2.mergeWith = mergeWith;
|
|
3781
|
+
let to;
|
|
3782
|
+
((to2) => {
|
|
3783
|
+
to2.Record = (m) => Object.fromEntries(m);
|
|
3784
|
+
})(to = Dict2.to || (Dict2.to = {}));
|
|
3785
|
+
Dict2.mapEntries = (f) => (data) => {
|
|
3786
|
+
const res = new globalThis.Map();
|
|
3787
|
+
for (const [k, v] of data) {
|
|
3788
|
+
const [nk, nv] = f(k, v);
|
|
3789
|
+
res.set(nk, nv);
|
|
3790
|
+
}
|
|
3791
|
+
return res;
|
|
3792
|
+
};
|
|
3793
|
+
Dict2.mapKeys = (f) => (data) => {
|
|
3794
|
+
const res = new globalThis.Map();
|
|
3795
|
+
for (const [k, v] of data) {
|
|
3796
|
+
res.set(f(k), v);
|
|
3797
|
+
}
|
|
3798
|
+
return res;
|
|
3799
|
+
};
|
|
3800
|
+
Dict2.NonEmpty = DictNonEmpty;
|
|
3801
|
+
})(Dict || (Dict = {}));
|
|
3802
|
+
|
|
3803
|
+
// src/Data/Json.ts
|
|
3804
|
+
var isSyntaxError = (err2) => typeof err2 === "object" && err2 !== null && "name" in err2 && err2.name === "SyntaxError";
|
|
3805
|
+
var isTypeError = (err2) => typeof err2 === "object" && err2 !== null && "name" in err2 && err2.name === "TypeError";
|
|
3806
|
+
var Json;
|
|
3807
|
+
((Json2) => {
|
|
3808
|
+
Json2.parse = (text) => Result.tryCatch(() => JSON.parse(text), {
|
|
3809
|
+
onError: (err2) => isSyntaxError(err2) ? err2 : new SyntaxError(String(err2))
|
|
3810
|
+
});
|
|
3811
|
+
Json2.stringify = (value, replacer, space) => Result.tryCatch(() => JSON.stringify(value, replacer, space), {
|
|
3812
|
+
onError: (err2) => isTypeError(err2) ? err2 : new TypeError(String(err2))
|
|
3813
|
+
});
|
|
3814
|
+
})(Json || (Json = {}));
|
|
3815
|
+
|
|
3816
|
+
// src/Data/Num.ts
|
|
3817
|
+
var Num;
|
|
3818
|
+
((Num2) => {
|
|
3819
|
+
let is;
|
|
3820
|
+
((is2) => {
|
|
3821
|
+
is2.zero = (n) => n === 0;
|
|
3822
|
+
is2.integer = (n) => Number.isInteger(n);
|
|
3823
|
+
is2.float = (n) => Number.isFinite(n) && !Number.isInteger(n);
|
|
3824
|
+
is2.finite = (n) => Number.isFinite(n);
|
|
3825
|
+
is2.nan = (n) => Number.isNaN(n);
|
|
3826
|
+
is2.even = (n) => Number.isInteger(n) && n % 2 === 0;
|
|
3827
|
+
is2.odd = (n) => Number.isInteger(n) && n % 2 !== 0;
|
|
3828
|
+
is2.positive = (n) => n > 0;
|
|
3829
|
+
is2.negative = (n) => n < 0;
|
|
3830
|
+
})(is = Num2.is || (Num2.is = {}));
|
|
3831
|
+
Num2.range = (from, to, step = 1) => {
|
|
3832
|
+
if (step <= 0 || from > to) {
|
|
3833
|
+
return [];
|
|
3834
|
+
}
|
|
3835
|
+
const count = Math.floor((to - from) / step) + 1;
|
|
3836
|
+
const result = new Array(count);
|
|
3837
|
+
for (let i = 0; i < count; i++) {
|
|
3838
|
+
result[i] = from + i * step;
|
|
3839
|
+
}
|
|
3840
|
+
return result;
|
|
3841
|
+
};
|
|
3842
|
+
Num2.clamp = (min2, max2) => (n) => Math.min(Math.max(n, min2), max2);
|
|
3843
|
+
Num2.between = (min2, max2) => (n) => n >= min2 && n <= max2;
|
|
3844
|
+
Num2.inRange = (start, end) => (n) => n >= start && n < end;
|
|
3845
|
+
Num2.parse = (s) => {
|
|
3846
|
+
if (s.trim() === "") {
|
|
3847
|
+
return Maybe.make.none();
|
|
3848
|
+
}
|
|
3849
|
+
const n = Number(s);
|
|
3850
|
+
return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
|
|
3851
|
+
};
|
|
3852
|
+
Num2.add = (b) => (a) => a + b;
|
|
3853
|
+
Num2.subtract = (b) => (a) => a - b;
|
|
3854
|
+
Num2.multiply = (b) => (a) => a * b;
|
|
3855
|
+
Num2.divide = (b) => (a) => b === 0 ? Maybe.make.none() : Maybe.make.some(a / b);
|
|
3856
|
+
Num2.abs = (n) => Math.abs(n);
|
|
3857
|
+
Num2.negate = (n) => -n;
|
|
3858
|
+
Num2.round = (n) => Math.round(n);
|
|
3859
|
+
Num2.floor = (n) => Math.floor(n);
|
|
3860
|
+
Num2.ceil = (n) => Math.ceil(n);
|
|
3861
|
+
Num2.remainder = (divisor) => (n) => divisor === 0 ? Maybe.make.none() : Maybe.make.some(n % divisor);
|
|
3862
|
+
Num2.sum = (ns) => {
|
|
3863
|
+
let result = 0;
|
|
3864
|
+
for (let i = 0; i < ns.length; i++) {
|
|
3865
|
+
result += ns[i];
|
|
3866
|
+
}
|
|
3867
|
+
return result;
|
|
3868
|
+
};
|
|
3869
|
+
Num2.mean = (ns) => ns.length === 0 ? Maybe.make.none() : Maybe.make.some((0, Num2.sum)(ns) / ns.length);
|
|
3870
|
+
Num2.min = (ns) => {
|
|
3871
|
+
if (ns.length === 0) {
|
|
3872
|
+
return Maybe.make.none();
|
|
3873
|
+
}
|
|
3874
|
+
let [result] = ns;
|
|
3875
|
+
for (let i = 1; i < ns.length; i++) {
|
|
3876
|
+
if (ns[i] < result) {
|
|
3877
|
+
result = ns[i];
|
|
3878
|
+
}
|
|
3879
|
+
}
|
|
3880
|
+
return Maybe.make.some(result);
|
|
3881
|
+
};
|
|
3882
|
+
Num2.max = (ns) => {
|
|
3883
|
+
if (ns.length === 0) {
|
|
3884
|
+
return Maybe.make.none();
|
|
3885
|
+
}
|
|
3886
|
+
let [result] = ns;
|
|
3887
|
+
for (let i = 1; i < ns.length; i++) {
|
|
3888
|
+
if (ns[i] > result) {
|
|
3889
|
+
result = ns[i];
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
return Maybe.make.some(result);
|
|
3893
|
+
};
|
|
3894
|
+
Num2.format = (options, locales) => (n) => !Number.isFinite(n) ? Maybe.make.none() : Maybe.make.some(new Intl.NumberFormat(locales, options).format(n));
|
|
3895
|
+
})(Num || (Num = {}));
|
|
3896
|
+
|
|
3897
|
+
// src/Data/Rec.ts
|
|
3898
|
+
var _isNonEmpty = (data) => Object.keys(data).length > 0;
|
|
3899
|
+
var RecMaybe;
|
|
3900
|
+
((RecMaybe2) => {
|
|
3901
|
+
RecMaybe2.traverse = (f) => (data) => {
|
|
3902
|
+
const recordKeys = Object.keys(data);
|
|
3903
|
+
const result = {};
|
|
3904
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
3905
|
+
const key = recordKeys[i];
|
|
3906
|
+
const maybeVal = f(data[key]);
|
|
3907
|
+
if (maybeVal.kind === "None") {
|
|
3908
|
+
return maybeVal;
|
|
3909
|
+
}
|
|
3910
|
+
Object.defineProperty(result, key, { value: maybeVal.value, writable: true, enumerable: true, configurable: true });
|
|
3911
|
+
}
|
|
3912
|
+
return { kind: "Some", value: result };
|
|
3913
|
+
};
|
|
3914
|
+
RecMaybe2.sequence = (data) => (0, RecMaybe2.traverse)((a) => a)(data);
|
|
3915
|
+
})(RecMaybe || (RecMaybe = {}));
|
|
3916
|
+
var RecResult;
|
|
3917
|
+
((RecResult2) => {
|
|
3918
|
+
RecResult2.traverse = (f) => (data) => {
|
|
3919
|
+
const recordKeys = Object.keys(data);
|
|
3920
|
+
const result = {};
|
|
3921
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
3922
|
+
const key = recordKeys[i];
|
|
3923
|
+
const res = f(data[key]);
|
|
3924
|
+
if (res.kind === "Err") {
|
|
3925
|
+
return res;
|
|
3926
|
+
}
|
|
3927
|
+
Object.defineProperty(result, key, { value: res.value, writable: true, enumerable: true, configurable: true });
|
|
3928
|
+
}
|
|
3929
|
+
return { kind: "Ok", value: result };
|
|
3930
|
+
};
|
|
3931
|
+
RecResult2.sequence = (data) => (0, RecResult2.traverse)((a) => a)(data);
|
|
3932
|
+
})(RecResult || (RecResult = {}));
|
|
3933
|
+
var RecNonEmpty;
|
|
3934
|
+
((RecNonEmpty2) => {
|
|
3935
|
+
RecNonEmpty2.singleton = (key, value) => ({ [key]: value });
|
|
3936
|
+
let from;
|
|
3937
|
+
((from2) => {
|
|
3938
|
+
from2.Record = (data) => _isNonEmpty(data) ? Maybe.make.some(data) : Maybe.make.none();
|
|
3939
|
+
})(from = RecNonEmpty2.from || (RecNonEmpty2.from = {}));
|
|
3940
|
+
RecNonEmpty2.keys = (data) => Rec.keys(data);
|
|
3941
|
+
RecNonEmpty2.values = (data) => Rec.values(data);
|
|
3942
|
+
RecNonEmpty2.entries = (data) => Rec.entries(data);
|
|
3943
|
+
RecNonEmpty2.reduce = (f) => (data) => (0, RecNonEmpty2.values)(data).reduce(f);
|
|
3944
|
+
RecNonEmpty2.map = (f) => (data) => Rec.map(f)(data);
|
|
3945
|
+
RecNonEmpty2.mapWithKey = (f) => (data) => Rec.mapWithKey(f)(data);
|
|
3946
|
+
})(RecNonEmpty || (RecNonEmpty = {}));
|
|
3947
|
+
var Rec;
|
|
3948
|
+
((Rec2) => {
|
|
3949
|
+
let is;
|
|
3950
|
+
((is2) => {
|
|
3951
|
+
is2.empty = (data) => Object.keys(data).length === 0;
|
|
3952
|
+
is2.nonEmpty = _isNonEmpty;
|
|
3953
|
+
})(is = Rec2.is || (Rec2.is = {}));
|
|
3954
|
+
Rec2.map = (f) => (data) => {
|
|
3955
|
+
const recordKeys = Object.keys(data);
|
|
3956
|
+
const recordValues = Object.values(data);
|
|
3957
|
+
const result = Object.create(Object.getPrototypeOf(data));
|
|
3958
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
3959
|
+
const key = recordKeys[i];
|
|
3960
|
+
if (key === "__proto__") {
|
|
3961
|
+
Object.defineProperty(result, "__proto__", {
|
|
3962
|
+
value: f(recordValues[i]),
|
|
3963
|
+
writable: true,
|
|
3964
|
+
enumerable: true,
|
|
3965
|
+
configurable: true
|
|
3966
|
+
});
|
|
3967
|
+
} else {
|
|
3968
|
+
result[key] = f(recordValues[i]);
|
|
3969
|
+
}
|
|
3970
|
+
}
|
|
3971
|
+
return result;
|
|
3972
|
+
};
|
|
3973
|
+
Rec2.filterMap = (f) => (data) => {
|
|
3974
|
+
const recordKeys = Object.keys(data);
|
|
3975
|
+
const recordValues = Object.values(data);
|
|
3976
|
+
const result = Object.create(Object.getPrototypeOf(data));
|
|
3977
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
3978
|
+
const maybeVal = f(recordValues[i]);
|
|
3979
|
+
if (maybeVal.kind === "Some") {
|
|
3980
|
+
Object.defineProperty(result, recordKeys[i], {
|
|
3981
|
+
value: maybeVal.value,
|
|
3982
|
+
writable: true,
|
|
3983
|
+
enumerable: true,
|
|
3984
|
+
configurable: true
|
|
3985
|
+
});
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3988
|
+
return result;
|
|
3989
|
+
};
|
|
3990
|
+
Rec2.mapWithKey = (f) => (data) => {
|
|
3991
|
+
const recordKeys = Object.keys(data);
|
|
3992
|
+
const recordValues = Object.values(data);
|
|
3993
|
+
const result = Object.create(Object.getPrototypeOf(data));
|
|
3994
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
3995
|
+
const key = recordKeys[i];
|
|
3996
|
+
if (key === "__proto__") {
|
|
3997
|
+
Object.defineProperty(result, "__proto__", {
|
|
3998
|
+
value: f(key, recordValues[i]),
|
|
3999
|
+
writable: true,
|
|
4000
|
+
enumerable: true,
|
|
4001
|
+
configurable: true
|
|
4002
|
+
});
|
|
4003
|
+
} else {
|
|
4004
|
+
result[key] = f(key, recordValues[i]);
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
return result;
|
|
4008
|
+
};
|
|
4009
|
+
Rec2.filter = (predicate) => (data) => {
|
|
4010
|
+
const recordKeys = Object.keys(data);
|
|
4011
|
+
const recordValues = Object.values(data);
|
|
4012
|
+
const result = Object.create(Object.getPrototypeOf(data));
|
|
4013
|
+
for (let i = 0; i < recordKeys.length; i++) {
|
|
4014
|
+
if (predicate(recordValues[i])) {
|
|
4015
|
+
Object.defineProperty(result, recordKeys[i], {
|
|
4016
|
+
value: recordValues[i],
|
|
4017
|
+
writable: true,
|
|
4018
|
+
enumerable: true,
|
|
4019
|
+
configurable: true
|
|
4020
|
+
});
|
|
4021
|
+
}
|
|
4022
|
+
}
|
|
4023
|
+
return result;
|
|
4024
|
+
};
|
|
4025
|
+
Rec2.filterWithKey = (predicate) => (data) => {
|
|
4026
|
+
const result = {};
|
|
4027
|
+
for (const [k, v] of Object.entries(data)) {
|
|
4028
|
+
if (predicate(k, v)) {
|
|
4029
|
+
Object.defineProperty(result, k, { value: v, writable: true, enumerable: true, configurable: true });
|
|
4030
|
+
}
|
|
4031
|
+
}
|
|
4032
|
+
return result;
|
|
4033
|
+
};
|
|
4034
|
+
Rec2.lookup = (key) => (data) => Object.hasOwn(data, key) ? { kind: "Some", value: data[key] } : { kind: "None" };
|
|
4035
|
+
Rec2.keys = (data) => Object.keys(data);
|
|
4036
|
+
Rec2.values = (data) => Object.values(data);
|
|
4037
|
+
Rec2.entries = (data) => Object.entries(data);
|
|
4038
|
+
let from;
|
|
4039
|
+
((from2) => {
|
|
4040
|
+
from2.entries = (data) => Object.fromEntries(data);
|
|
4041
|
+
})(from = Rec2.from || (Rec2.from = {}));
|
|
4042
|
+
Rec2.groupBy = (keyFn) => (items) => {
|
|
4043
|
+
const result = {};
|
|
4044
|
+
for (const item of items) {
|
|
4045
|
+
const key = keyFn(item);
|
|
4046
|
+
if (Object.hasOwn(result, key)) {
|
|
4047
|
+
result[key].push(item);
|
|
4048
|
+
} else {
|
|
4049
|
+
Object.defineProperty(result, key, { value: [item], writable: true, enumerable: true, configurable: true });
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
return result;
|
|
4053
|
+
};
|
|
4054
|
+
Rec2.pick = (...pickedKeys) => (data) => {
|
|
4055
|
+
const result = {};
|
|
4056
|
+
for (const key of pickedKeys) {
|
|
4057
|
+
if (Object.hasOwn(data, key)) {
|
|
4058
|
+
Object.defineProperty(result, key, { value: data[key], writable: true, enumerable: true, configurable: true });
|
|
4059
|
+
}
|
|
4060
|
+
}
|
|
4061
|
+
return result;
|
|
4062
|
+
};
|
|
4063
|
+
Rec2.omit = (...omittedKeys) => (data) => {
|
|
4064
|
+
const omitSet = new Set(omittedKeys);
|
|
4065
|
+
const result = {};
|
|
4066
|
+
for (const key of Object.keys(data)) {
|
|
4067
|
+
if (!omitSet.has(key)) {
|
|
4068
|
+
Object.defineProperty(result, key, {
|
|
4069
|
+
value: data[key],
|
|
4070
|
+
writable: true,
|
|
4071
|
+
enumerable: true,
|
|
4072
|
+
configurable: true
|
|
4073
|
+
});
|
|
4074
|
+
}
|
|
4075
|
+
}
|
|
4076
|
+
return result;
|
|
4077
|
+
};
|
|
4078
|
+
Rec2.merge = (other) => (data) => ({
|
|
4079
|
+
...data,
|
|
4080
|
+
...other
|
|
4081
|
+
});
|
|
4082
|
+
function mergeWith(combine) {
|
|
4083
|
+
return (arg1, arg2) => {
|
|
4084
|
+
if (arg2 !== void 0) {
|
|
4085
|
+
const first = arg1;
|
|
4086
|
+
const second2 = arg2;
|
|
4087
|
+
const result = { ...first };
|
|
4088
|
+
for (const [k, v] of Object.entries(second2)) {
|
|
4089
|
+
if (Object.hasOwn(result, k)) {
|
|
4090
|
+
result[k] = combine(result[k], v);
|
|
4091
|
+
} else {
|
|
4092
|
+
result[k] = v;
|
|
4093
|
+
}
|
|
4094
|
+
}
|
|
4095
|
+
return result;
|
|
4096
|
+
}
|
|
4097
|
+
const second = arg1;
|
|
4098
|
+
return (first) => {
|
|
4099
|
+
const result = { ...first };
|
|
4100
|
+
for (const [k, v] of Object.entries(second)) {
|
|
4101
|
+
if (Object.hasOwn(result, k)) {
|
|
4102
|
+
result[k] = combine(result[k], v);
|
|
4103
|
+
} else {
|
|
4104
|
+
result[k] = v;
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
return result;
|
|
4108
|
+
};
|
|
4109
|
+
};
|
|
4110
|
+
}
|
|
4111
|
+
Rec2.mergeWith = mergeWith;
|
|
4112
|
+
Rec2.size = (data) => Object.keys(data).length;
|
|
4113
|
+
Rec2.mapKeys = (f) => (data) => {
|
|
4114
|
+
const result = {};
|
|
4115
|
+
for (const [k, v] of Object.entries(data)) {
|
|
4116
|
+
Object.defineProperty(result, f(k), { value: v, writable: true, enumerable: true, configurable: true });
|
|
4117
|
+
}
|
|
4118
|
+
return result;
|
|
4119
|
+
};
|
|
4120
|
+
Rec2.compact = (data) => {
|
|
4121
|
+
const result = {};
|
|
4122
|
+
for (const [k, v] of Object.entries(data)) {
|
|
4123
|
+
if (v.kind === "Some") {
|
|
4124
|
+
Object.defineProperty(result, k, { value: v.value, writable: true, enumerable: true, configurable: true });
|
|
4125
|
+
}
|
|
4126
|
+
}
|
|
4127
|
+
return result;
|
|
4128
|
+
};
|
|
4129
|
+
Rec2.mapEntries = (f) => (data) => {
|
|
4130
|
+
const result = {};
|
|
4131
|
+
for (const [k, v] of Object.entries(data)) {
|
|
4132
|
+
const [newKey, newVal] = f(k, v);
|
|
4133
|
+
Object.defineProperty(result, newKey, { value: newVal, writable: true, enumerable: true, configurable: true });
|
|
4134
|
+
}
|
|
4135
|
+
return result;
|
|
4136
|
+
};
|
|
4137
|
+
Rec2.updateIn = (path, f) => (data) => {
|
|
4138
|
+
const updateNode = (obj, keys2) => {
|
|
4139
|
+
const [head, ...tail] = keys2;
|
|
4140
|
+
if (tail.length === 0) {
|
|
4141
|
+
return { ...obj, [head]: f(obj?.[head]) };
|
|
4142
|
+
}
|
|
4143
|
+
const child = obj && typeof obj === "object" && head in obj ? obj[head] : {};
|
|
4144
|
+
return { ...obj, [head]: updateNode(child, tail) };
|
|
4145
|
+
};
|
|
4146
|
+
return updateNode(data, path);
|
|
4147
|
+
};
|
|
4148
|
+
let traverse;
|
|
4149
|
+
((traverse2) => {
|
|
4150
|
+
traverse2.Maybe = RecMaybe.traverse;
|
|
4151
|
+
traverse2.Result = RecResult.traverse;
|
|
4152
|
+
})(traverse = Rec2.traverse || (Rec2.traverse = {}));
|
|
4153
|
+
let sequence;
|
|
4154
|
+
((sequence2) => {
|
|
4155
|
+
sequence2.Maybe = RecMaybe.sequence;
|
|
4156
|
+
sequence2.Result = RecResult.sequence;
|
|
4157
|
+
})(sequence = Rec2.sequence || (Rec2.sequence = {}));
|
|
4158
|
+
Rec2.NonEmpty = RecNonEmpty;
|
|
4159
|
+
})(Rec || (Rec = {}));
|
|
4160
|
+
|
|
4161
|
+
// src/Data/Str.ts
|
|
4162
|
+
var StrNonEmpty;
|
|
4163
|
+
((StrNonEmpty2) => {
|
|
4164
|
+
let from;
|
|
4165
|
+
((from2) => {
|
|
4166
|
+
from2.String = (s) => s.length > 0 ? Maybe.make.some(s) : Maybe.make.none();
|
|
4167
|
+
})(from = StrNonEmpty2.from || (StrNonEmpty2.from = {}));
|
|
4168
|
+
})(StrNonEmpty || (StrNonEmpty = {}));
|
|
4169
|
+
var Str;
|
|
4170
|
+
((Str2) => {
|
|
4171
|
+
let is;
|
|
4172
|
+
((is2) => {
|
|
4173
|
+
is2.empty = (s) => s.length === 0;
|
|
4174
|
+
is2.nonEmpty = (s) => s.length > 0;
|
|
4175
|
+
})(is = Str2.is || (Str2.is = {}));
|
|
4176
|
+
Str2.split = (separator) => (s) => s.split(separator);
|
|
4177
|
+
Str2.trim = (s) => s.trim();
|
|
4178
|
+
Str2.includes = (substring) => (s) => s.includes(substring);
|
|
4179
|
+
Str2.replace = (pattern, replacement) => (s) => s.replace(pattern, replacement);
|
|
4180
|
+
Str2.replaceAll = (pattern, replacement) => (s) => s.replaceAll(pattern, replacement);
|
|
4181
|
+
Str2.startsWith = (prefix) => (s) => s.startsWith(prefix);
|
|
4182
|
+
Str2.endsWith = (suffix) => (s) => s.endsWith(suffix);
|
|
4183
|
+
Str2.toUpperCase = (s) => s.toUpperCase();
|
|
4184
|
+
Str2.toLowerCase = (s) => s.toLowerCase();
|
|
4185
|
+
Str2.capitalize = (s) => s.length === 0 ? "" : s.charAt(0).toUpperCase() + s.slice(1);
|
|
4186
|
+
Str2.lines = (s) => s.split(/\r?\n|\r/);
|
|
4187
|
+
Str2.words = (s) => s.trim().split(/\s+/).filter(Boolean);
|
|
4188
|
+
Str2.isBlank = (s) => s.trim().length === 0;
|
|
4189
|
+
Str2.length = (s) => s.length;
|
|
4190
|
+
Str2.slice = (start, end) => (s) => s.slice(start, end);
|
|
4191
|
+
Str2.padStart = (maxLength, fillString) => (s) => s.padStart(maxLength, fillString);
|
|
4192
|
+
Str2.padEnd = (maxLength, fillString) => (s) => s.padEnd(maxLength, fillString);
|
|
4193
|
+
Str2.parse = {
|
|
4194
|
+
/**
|
|
4195
|
+
* Parses a string as an integer (base 10). Returns `None` if the result is `NaN`.
|
|
4196
|
+
*
|
|
4197
|
+
* @example
|
|
4198
|
+
* ```ts
|
|
4199
|
+
* Str.parse.int("42"); // Some(42)
|
|
4200
|
+
* Str.parse.int("3.7"); // Some(3)
|
|
4201
|
+
* Str.parse.int("abc"); // None
|
|
4202
|
+
* ```
|
|
4203
|
+
*/
|
|
4204
|
+
int: (s) => {
|
|
4205
|
+
const n = parseInt(s, 10);
|
|
4206
|
+
return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
|
|
4207
|
+
},
|
|
4208
|
+
/**
|
|
4209
|
+
* Parses a string as a floating-point number. Returns `None` if the result is `NaN`.
|
|
4210
|
+
*
|
|
4211
|
+
* @example
|
|
4212
|
+
* ```ts
|
|
4213
|
+
* Str.parse.float("3.14"); // Some(3.14)
|
|
4214
|
+
* Str.parse.float("42"); // Some(42)
|
|
4215
|
+
* Str.parse.float("abc"); // None
|
|
4216
|
+
* ```
|
|
4217
|
+
*/
|
|
4218
|
+
float: (s) => {
|
|
4219
|
+
const n = parseFloat(s);
|
|
4220
|
+
return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
|
|
4221
|
+
}
|
|
4222
|
+
};
|
|
4223
|
+
Str2.parseJson = (s) => {
|
|
4224
|
+
try {
|
|
4225
|
+
return Result.make.ok(JSON.parse(s));
|
|
4226
|
+
} catch (error) {
|
|
4227
|
+
return Result.make.err(error);
|
|
4228
|
+
}
|
|
4229
|
+
};
|
|
4230
|
+
Str2.uncapitalize = (s) => s.length === 0 ? "" : s.charAt(0).toLowerCase() + s.slice(1);
|
|
4231
|
+
Str2.truncate = (options) => (s) => {
|
|
4232
|
+
const { length: targetLength, suffix = "..." } = options;
|
|
4233
|
+
if (s.length <= targetLength) {
|
|
4234
|
+
return s;
|
|
4235
|
+
}
|
|
4236
|
+
if (targetLength <= suffix.length) {
|
|
4237
|
+
return suffix.slice(0, targetLength);
|
|
4238
|
+
}
|
|
4239
|
+
return s.slice(0, targetLength - suffix.length) + suffix;
|
|
4240
|
+
};
|
|
4241
|
+
Str2.NonEmpty = StrNonEmpty;
|
|
4242
|
+
})(Str || (Str = {}));
|
|
4243
|
+
|
|
4244
|
+
// src/Data/Uniq.ts
|
|
4245
|
+
var UniqNonEmpty;
|
|
4246
|
+
((UniqNonEmpty2) => {
|
|
4247
|
+
UniqNonEmpty2.singleton = (item) => new globalThis.Set([item]);
|
|
4248
|
+
let from;
|
|
4249
|
+
((from2) => {
|
|
4250
|
+
from2.Set = (s) => s.size > 0 ? Maybe.make.some(s) : Maybe.make.none();
|
|
4251
|
+
})(from = UniqNonEmpty2.from || (UniqNonEmpty2.from = {}));
|
|
4252
|
+
UniqNonEmpty2.reduce = (f) => (s) => to.Array(s).reduce(f);
|
|
4253
|
+
UniqNonEmpty2.map = (f) => (s) => Uniq.map(f)(s);
|
|
4254
|
+
let to;
|
|
4255
|
+
((to2) => {
|
|
4256
|
+
to2.Array = (s) => Uniq.to.Array(s);
|
|
4257
|
+
})(to = UniqNonEmpty2.to || (UniqNonEmpty2.to = {}));
|
|
4258
|
+
})(UniqNonEmpty || (UniqNonEmpty = {}));
|
|
4259
|
+
var Uniq;
|
|
4260
|
+
((Uniq2) => {
|
|
4261
|
+
let is;
|
|
4262
|
+
((is2) => {
|
|
4263
|
+
is2.empty = (s) => s.size === 0;
|
|
4264
|
+
is2.nonEmpty = (s) => s.size > 0;
|
|
4265
|
+
})(is = Uniq2.is || (Uniq2.is = {}));
|
|
4266
|
+
Uniq2.empty = () => new globalThis.Set();
|
|
4267
|
+
Uniq2.singleton = (item) => new globalThis.Set([item]);
|
|
4268
|
+
let from;
|
|
4269
|
+
((from2) => {
|
|
4270
|
+
from2.Array = (arr) => new globalThis.Set(arr);
|
|
4271
|
+
})(from = Uniq2.from || (Uniq2.from = {}));
|
|
4272
|
+
Uniq2.has = (item) => (s) => s.has(item);
|
|
4273
|
+
Uniq2.size = (s) => s.size;
|
|
4274
|
+
Uniq2.isSubsetOf = (other) => (s) => {
|
|
4275
|
+
const set = s;
|
|
4276
|
+
if (typeof set.isSubsetOf === "function") {
|
|
4277
|
+
return set.isSubsetOf(other);
|
|
4278
|
+
}
|
|
4279
|
+
for (const item of s) {
|
|
4280
|
+
if (!other.has(item)) {
|
|
4281
|
+
return false;
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
return true;
|
|
4285
|
+
};
|
|
4286
|
+
Uniq2.insert = (item) => (s) => {
|
|
4287
|
+
if (s.has(item)) {
|
|
4288
|
+
return s;
|
|
4289
|
+
}
|
|
4290
|
+
const result = new globalThis.Set(s);
|
|
4291
|
+
result.add(item);
|
|
4292
|
+
return result;
|
|
4293
|
+
};
|
|
4294
|
+
Uniq2.remove = (item) => (s) => {
|
|
4295
|
+
if (!s.has(item)) {
|
|
4296
|
+
return s;
|
|
4297
|
+
}
|
|
4298
|
+
const result = new globalThis.Set(s);
|
|
4299
|
+
result.delete(item);
|
|
4300
|
+
return result;
|
|
4301
|
+
};
|
|
4302
|
+
Uniq2.map = (f) => (s) => {
|
|
4303
|
+
const result = new globalThis.Set();
|
|
4304
|
+
for (const item of s) {
|
|
4305
|
+
result.add(f(item));
|
|
4306
|
+
}
|
|
4307
|
+
return result;
|
|
4308
|
+
};
|
|
4309
|
+
Uniq2.filter = (predicate) => (s) => {
|
|
4310
|
+
const result = new globalThis.Set();
|
|
4311
|
+
for (const item of s) {
|
|
4312
|
+
if (predicate(item)) {
|
|
4313
|
+
result.add(item);
|
|
4314
|
+
}
|
|
4315
|
+
}
|
|
4316
|
+
return result;
|
|
4317
|
+
};
|
|
4318
|
+
Uniq2.union = (other) => (s) => {
|
|
4319
|
+
const set = s;
|
|
4320
|
+
if (typeof set.union === "function") {
|
|
4321
|
+
return set.union(other);
|
|
4322
|
+
}
|
|
4323
|
+
const result = new globalThis.Set(s);
|
|
4324
|
+
for (const item of other) {
|
|
4325
|
+
result.add(item);
|
|
4326
|
+
}
|
|
4327
|
+
return result;
|
|
4328
|
+
};
|
|
4329
|
+
Uniq2.intersection = (other) => (s) => {
|
|
4330
|
+
const set = s;
|
|
4331
|
+
if (typeof set.intersection === "function") {
|
|
4332
|
+
return set.intersection(other);
|
|
4333
|
+
}
|
|
4334
|
+
const result = new globalThis.Set();
|
|
4335
|
+
for (const item of s) {
|
|
4336
|
+
if (other.has(item)) {
|
|
4337
|
+
result.add(item);
|
|
4338
|
+
}
|
|
4339
|
+
}
|
|
4340
|
+
return result;
|
|
4341
|
+
};
|
|
4342
|
+
Uniq2.difference = (other) => (s) => {
|
|
4343
|
+
const set = s;
|
|
4344
|
+
if (typeof set.difference === "function") {
|
|
4345
|
+
return set.difference(other);
|
|
4346
|
+
}
|
|
4347
|
+
const result = new globalThis.Set();
|
|
4348
|
+
for (const item of s) {
|
|
4349
|
+
if (!other.has(item)) {
|
|
4350
|
+
result.add(item);
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
return result;
|
|
4354
|
+
};
|
|
4355
|
+
Uniq2.reduce = (init, f) => (s) => {
|
|
4356
|
+
let acc = init;
|
|
4357
|
+
for (const item of s) {
|
|
4358
|
+
acc = f(acc, item);
|
|
4359
|
+
}
|
|
4360
|
+
return acc;
|
|
4361
|
+
};
|
|
4362
|
+
let to;
|
|
4363
|
+
((to2) => {
|
|
4364
|
+
to2.Array = (s) => [...s];
|
|
4365
|
+
})(to = Uniq2.to || (Uniq2.to = {}));
|
|
4366
|
+
Uniq2.NonEmpty = UniqNonEmpty;
|
|
4367
|
+
})(Uniq || (Uniq = {}));
|
|
4368
|
+
export {
|
|
4369
|
+
Arr,
|
|
4370
|
+
BigNum,
|
|
4371
|
+
Brand,
|
|
4372
|
+
Combinable,
|
|
4373
|
+
Deferred,
|
|
4374
|
+
Dict,
|
|
4375
|
+
Duration,
|
|
4376
|
+
Equality,
|
|
4377
|
+
Json,
|
|
4378
|
+
Lazy,
|
|
4379
|
+
Lens,
|
|
4380
|
+
Logged,
|
|
4381
|
+
Maybe,
|
|
4382
|
+
Num,
|
|
4383
|
+
Op,
|
|
4384
|
+
Optional,
|
|
4385
|
+
Ordering,
|
|
4386
|
+
Pair,
|
|
4387
|
+
Predicate,
|
|
4388
|
+
Reader,
|
|
4389
|
+
Rec,
|
|
4390
|
+
Refinement,
|
|
4391
|
+
RemoteData,
|
|
4392
|
+
Resource,
|
|
4393
|
+
Result,
|
|
4394
|
+
RetryPolicy,
|
|
4395
|
+
State,
|
|
4396
|
+
Str,
|
|
4397
|
+
Stream,
|
|
4398
|
+
Task,
|
|
4399
|
+
These,
|
|
4400
|
+
Uniq,
|
|
4401
|
+
Validation,
|
|
4402
|
+
and,
|
|
4403
|
+
compose,
|
|
4404
|
+
constFalse,
|
|
4405
|
+
constNull,
|
|
4406
|
+
constTrue,
|
|
4407
|
+
constUndefined,
|
|
4408
|
+
constVoid,
|
|
4409
|
+
constant,
|
|
4410
|
+
converge,
|
|
4411
|
+
curry,
|
|
4412
|
+
curry3,
|
|
4413
|
+
curry4,
|
|
4414
|
+
defaultTo,
|
|
4415
|
+
flip,
|
|
4416
|
+
flow,
|
|
4417
|
+
identity,
|
|
4418
|
+
juxt,
|
|
4419
|
+
memoize,
|
|
4420
|
+
memoizeWeak,
|
|
4421
|
+
not,
|
|
4422
|
+
on,
|
|
4423
|
+
once,
|
|
4424
|
+
or,
|
|
4425
|
+
pipe,
|
|
4426
|
+
tap,
|
|
4427
|
+
tuple,
|
|
4428
|
+
uncurry,
|
|
4429
|
+
uncurry3,
|
|
4430
|
+
uncurry4,
|
|
4431
|
+
untuple
|
|
4432
|
+
};
|