@nlozgachev/pipelined 0.13.0 → 0.15.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/dist/index.js ADDED
@@ -0,0 +1,1563 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Arr: () => Arr,
24
+ Brand: () => Brand,
25
+ Deferred: () => Deferred,
26
+ Dict: () => Dict,
27
+ Lens: () => Lens,
28
+ Logged: () => Logged,
29
+ Num: () => Num,
30
+ Option: () => Option,
31
+ Optional: () => Optional,
32
+ Predicate: () => Predicate,
33
+ Reader: () => Reader,
34
+ Rec: () => Rec,
35
+ Refinement: () => Refinement,
36
+ RemoteData: () => RemoteData,
37
+ Resource: () => Resource,
38
+ Result: () => Result,
39
+ State: () => State,
40
+ Str: () => Str,
41
+ Task: () => Task,
42
+ TaskOption: () => TaskOption,
43
+ TaskResult: () => TaskResult,
44
+ TaskValidation: () => TaskValidation,
45
+ These: () => These,
46
+ Tuple: () => Tuple,
47
+ Uniq: () => Uniq,
48
+ Validation: () => Validation,
49
+ and: () => and,
50
+ compose: () => compose,
51
+ constFalse: () => constFalse,
52
+ constNull: () => constNull,
53
+ constTrue: () => constTrue,
54
+ constUndefined: () => constUndefined,
55
+ constVoid: () => constVoid,
56
+ constant: () => constant,
57
+ converge: () => converge,
58
+ curry: () => curry,
59
+ curry3: () => curry3,
60
+ curry4: () => curry4,
61
+ flip: () => flip,
62
+ flow: () => flow,
63
+ identity: () => identity,
64
+ isNonEmptyList: () => isNonEmptyList,
65
+ juxt: () => juxt,
66
+ memoize: () => memoize,
67
+ memoizeWeak: () => memoizeWeak,
68
+ not: () => not,
69
+ on: () => on,
70
+ once: () => once,
71
+ or: () => or,
72
+ pipe: () => pipe,
73
+ tap: () => tap,
74
+ uncurry: () => uncurry,
75
+ uncurry3: () => uncurry3,
76
+ uncurry4: () => uncurry4
77
+ });
78
+ module.exports = __toCommonJS(src_exports);
79
+
80
+ // src/Composition/compose.ts
81
+ function compose(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9) {
82
+ const len = arguments.length;
83
+ switch (len) {
84
+ case 1:
85
+ return f0;
86
+ case 2:
87
+ return function() {
88
+ return f0(f1.apply(this, arguments));
89
+ };
90
+ case 3:
91
+ return function() {
92
+ return f0(f1(f2.apply(this, arguments)));
93
+ };
94
+ case 4:
95
+ return function() {
96
+ return f0(f1(f2(f3.apply(this, arguments))));
97
+ };
98
+ case 5:
99
+ return function() {
100
+ return f0(f1(f2(f3(f4.apply(this, arguments)))));
101
+ };
102
+ case 6:
103
+ return function() {
104
+ return f0(f1(f2(f3(f4(f5.apply(this, arguments))))));
105
+ };
106
+ case 7:
107
+ return function() {
108
+ return f0(f1(f2(f3(f4(f5(f6.apply(this, arguments)))))));
109
+ };
110
+ case 8:
111
+ return function() {
112
+ return f0(f1(f2(f3(f4(f5(f6(f7.apply(this, arguments))))))));
113
+ };
114
+ case 9:
115
+ return function() {
116
+ return f0(f1(f2(f3(f4(f5(f6(f7(f8.apply(this, arguments)))))))));
117
+ };
118
+ case 10:
119
+ return function() {
120
+ return f0(f1(f2(f3(f4(f5(f6(f7(f8(f9.apply(this, arguments))))))))));
121
+ };
122
+ }
123
+ return f0;
124
+ }
125
+
126
+ // src/Composition/converge.ts
127
+ function converge(f, transformers) {
128
+ return (a) => f(...transformers.map((t) => t(a)));
129
+ }
130
+
131
+ // src/Composition/curry.ts
132
+ var curry = (f) => (a) => (b) => f(a, b);
133
+ var curry3 = (f) => (a) => (b) => (c) => f(a, b, c);
134
+ var curry4 = (f) => (a) => (b) => (c) => (d) => f(a, b, c, d);
135
+
136
+ // src/Composition/flip.ts
137
+ var flip = (f) => (b) => (a) => f(a)(b);
138
+
139
+ // src/Composition/flow.ts
140
+ function flow(ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
141
+ const len = arguments.length;
142
+ switch (len) {
143
+ case 0:
144
+ return function(...args) {
145
+ return args[0];
146
+ };
147
+ case 1:
148
+ return ab;
149
+ case 2:
150
+ return function() {
151
+ return bc(ab.apply(this, arguments));
152
+ };
153
+ case 3:
154
+ return function() {
155
+ return cd(bc(ab.apply(this, arguments)));
156
+ };
157
+ case 4:
158
+ return function() {
159
+ return de(cd(bc(ab.apply(this, arguments))));
160
+ };
161
+ case 5:
162
+ return function() {
163
+ return ef(de(cd(bc(ab.apply(this, arguments)))));
164
+ };
165
+ case 6:
166
+ return function() {
167
+ return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
168
+ };
169
+ case 7:
170
+ return function() {
171
+ return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
172
+ };
173
+ case 8:
174
+ return function() {
175
+ return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
176
+ };
177
+ case 9:
178
+ return function() {
179
+ return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
180
+ };
181
+ case 10:
182
+ return function() {
183
+ return jk(ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))))));
184
+ };
185
+ }
186
+ return ab;
187
+ }
188
+
189
+ // src/Composition/fn.ts
190
+ var identity = (a) => a;
191
+ var constant = (a) => () => a;
192
+ var constTrue = () => true;
193
+ var constFalse = () => false;
194
+ var constNull = () => null;
195
+ var constUndefined = () => void 0;
196
+ var constVoid = () => {
197
+ };
198
+ var and = (p1, p2) => (...args) => p1(...args) && p2(...args);
199
+ var or = (p1, p2) => (...args) => p1(...args) || p2(...args);
200
+ var once = (f) => {
201
+ let called = false;
202
+ let result;
203
+ return () => {
204
+ if (!called) {
205
+ result = f();
206
+ called = true;
207
+ }
208
+ return result;
209
+ };
210
+ };
211
+
212
+ // src/Composition/juxt.ts
213
+ function juxt(fns) {
214
+ return (a) => fns.map((f) => f(a));
215
+ }
216
+
217
+ // src/Composition/memoize.ts
218
+ var memoize = (f, keyFn = (a) => a) => {
219
+ const cache = /* @__PURE__ */ new Map();
220
+ return (a) => {
221
+ const key = keyFn(a);
222
+ if (cache.has(key)) {
223
+ return cache.get(key);
224
+ }
225
+ const result = f(a);
226
+ cache.set(key, result);
227
+ return result;
228
+ };
229
+ };
230
+ var memoizeWeak = (f) => {
231
+ const cache = /* @__PURE__ */ new WeakMap();
232
+ return (a) => {
233
+ if (cache.has(a)) {
234
+ return cache.get(a);
235
+ }
236
+ const result = f(a);
237
+ cache.set(a, result);
238
+ return result;
239
+ };
240
+ };
241
+
242
+ // src/Composition/not.ts
243
+ var not = (predicate) => (...args) => !predicate(...args);
244
+
245
+ // src/Composition/on.ts
246
+ var on = (f, g) => (a, b) => f(g(a), g(b));
247
+
248
+ // src/Composition/pipe.ts
249
+ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
250
+ const len = arguments.length;
251
+ switch (len) {
252
+ case 1:
253
+ return a;
254
+ case 2:
255
+ return ab(a);
256
+ case 3:
257
+ return bc(ab(a));
258
+ case 4:
259
+ return cd(bc(ab(a)));
260
+ case 5:
261
+ return de(cd(bc(ab(a))));
262
+ case 6:
263
+ return ef(de(cd(bc(ab(a)))));
264
+ case 7:
265
+ return fg(ef(de(cd(bc(ab(a))))));
266
+ case 8:
267
+ return gh(fg(ef(de(cd(bc(ab(a)))))));
268
+ case 9:
269
+ return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
270
+ case 10:
271
+ return ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))));
272
+ case 11:
273
+ return jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))));
274
+ }
275
+ }
276
+
277
+ // src/Composition/tap.ts
278
+ var tap = (f) => (a) => {
279
+ f(a);
280
+ return a;
281
+ };
282
+
283
+ // src/Composition/uncurry.ts
284
+ function uncurry(f) {
285
+ return (...args) => {
286
+ const inner = f(...args.slice(0, f.length));
287
+ return inner.length === 0 ? inner() : inner(...args.slice(f.length));
288
+ };
289
+ }
290
+ var uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
291
+ var uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
292
+
293
+ // src/Core/Deferred.ts
294
+ var _store = /* @__PURE__ */ new WeakMap();
295
+ var Deferred;
296
+ ((Deferred2) => {
297
+ Deferred2.fromPromise = (p) => {
298
+ const d = { then: ((f) => p.then(f)) };
299
+ _store.set(d, p);
300
+ return d;
301
+ };
302
+ Deferred2.toPromise = (d) => _store.get(d) ?? new Promise((resolve) => d.then(resolve));
303
+ })(Deferred || (Deferred = {}));
304
+
305
+ // src/Core/Lens.ts
306
+ var Lens;
307
+ ((Lens2) => {
308
+ Lens2.make = (get2, set2) => ({ get: get2, set: set2 });
309
+ Lens2.prop = () => (key) => (0, Lens2.make)(
310
+ (s) => s[key],
311
+ (a) => (s) => ({ ...s, [key]: a })
312
+ );
313
+ Lens2.get = (lens) => (s) => lens.get(s);
314
+ Lens2.set = (lens) => (a) => (s) => lens.set(a)(s);
315
+ Lens2.modify = (lens) => (f) => (s) => lens.set(f(lens.get(s)))(s);
316
+ Lens2.andThen = (inner) => (outer) => (0, Lens2.make)(
317
+ (s) => inner.get(outer.get(s)),
318
+ (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
319
+ );
320
+ Lens2.andThenOptional = (inner) => (outer) => ({
321
+ get: (s) => inner.get(outer.get(s)),
322
+ set: (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
323
+ });
324
+ Lens2.toOptional = (lens) => ({
325
+ get: (s) => ({ kind: "Some", value: lens.get(s) }),
326
+ set: lens.set
327
+ });
328
+ })(Lens || (Lens = {}));
329
+
330
+ // src/Core/Logged.ts
331
+ var Logged;
332
+ ((Logged2) => {
333
+ Logged2.make = (value) => ({ value, log: [] });
334
+ Logged2.tell = (entry) => ({ value: void 0, log: [entry] });
335
+ Logged2.map = (f) => (data) => ({
336
+ value: f(data.value),
337
+ log: data.log
338
+ });
339
+ Logged2.chain = (f) => (data) => {
340
+ const next = f(data.value);
341
+ return { value: next.value, log: [...data.log, ...next.log] };
342
+ };
343
+ Logged2.ap = (arg) => (data) => ({
344
+ value: data.value(arg.value),
345
+ log: [...data.log, ...arg.log]
346
+ });
347
+ Logged2.tap = (f) => (data) => {
348
+ f(data.value);
349
+ return data;
350
+ };
351
+ Logged2.run = (data) => [data.value, data.log];
352
+ })(Logged || (Logged = {}));
353
+
354
+ // src/Core/Result.ts
355
+ var Result;
356
+ ((Result2) => {
357
+ Result2.ok = (value) => ({ kind: "Ok", value });
358
+ Result2.err = (error) => ({ kind: "Error", error });
359
+ Result2.isOk = (data) => data.kind === "Ok";
360
+ Result2.isErr = (data) => data.kind === "Error";
361
+ Result2.tryCatch = (f, onError) => {
362
+ try {
363
+ return (0, Result2.ok)(f());
364
+ } catch (e) {
365
+ return (0, Result2.err)(onError(e));
366
+ }
367
+ };
368
+ Result2.map = (f) => (data) => (0, Result2.isOk)(data) ? (0, Result2.ok)(f(data.value)) : data;
369
+ Result2.mapError = (f) => (data) => (0, Result2.isErr)(data) ? (0, Result2.err)(f(data.error)) : data;
370
+ Result2.chain = (f) => (data) => (0, Result2.isOk)(data) ? f(data.value) : data;
371
+ Result2.fold = (onErr, onOk) => (data) => (0, Result2.isOk)(data) ? onOk(data.value) : onErr(data.error);
372
+ Result2.match = (cases) => (data) => (0, Result2.isOk)(data) ? cases.ok(data.value) : cases.err(data.error);
373
+ Result2.getOrElse = (defaultValue) => (data) => (0, Result2.isOk)(data) ? data.value : defaultValue();
374
+ Result2.tap = (f) => (data) => {
375
+ if ((0, Result2.isOk)(data)) f(data.value);
376
+ return data;
377
+ };
378
+ Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
379
+ Result2.recoverUnless = (blockedErr, fallback) => (data) => (0, Result2.isErr)(data) && data.error !== blockedErr ? fallback() : data;
380
+ Result2.toOption = (data) => (0, Result2.isOk)(data) ? Option.some(data.value) : Option.none();
381
+ Result2.ap = (arg) => (data) => (0, Result2.isOk)(data) && (0, Result2.isOk)(arg) ? (0, Result2.ok)(data.value(arg.value)) : (0, Result2.isErr)(data) ? data : arg;
382
+ })(Result || (Result = {}));
383
+
384
+ // src/Core/Option.ts
385
+ var _none = { kind: "None" };
386
+ var Option;
387
+ ((Option2) => {
388
+ Option2.some = (value) => ({ kind: "Some", value });
389
+ Option2.isSome = (data) => data.kind === "Some";
390
+ Option2.none = () => _none;
391
+ Option2.isNone = (data) => data.kind === "None";
392
+ Option2.fromNullable = (value) => value === null || value === void 0 ? (0, Option2.none)() : (0, Option2.some)(value);
393
+ Option2.toNullable = (data) => (0, Option2.isSome)(data) ? data.value : null;
394
+ Option2.toUndefined = (data) => (0, Option2.isSome)(data) ? data.value : void 0;
395
+ Option2.fromUndefined = (value) => value === void 0 ? (0, Option2.none)() : (0, Option2.some)(value);
396
+ Option2.toResult = (onNone) => (data) => (0, Option2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
397
+ Option2.fromResult = (data) => Result.isOk(data) ? (0, Option2.some)(data.value) : (0, Option2.none)();
398
+ Option2.map = (f) => (data) => (0, Option2.isSome)(data) ? (0, Option2.some)(f(data.value)) : data;
399
+ Option2.chain = (f) => (data) => (0, Option2.isSome)(data) ? f(data.value) : data;
400
+ Option2.fold = (onNone, onSome) => (data) => (0, Option2.isSome)(data) ? onSome(data.value) : onNone();
401
+ Option2.match = (cases) => (data) => (0, Option2.isSome)(data) ? cases.some(data.value) : cases.none();
402
+ Option2.getOrElse = (defaultValue) => (data) => (0, Option2.isSome)(data) ? data.value : defaultValue();
403
+ Option2.tap = (f) => (data) => {
404
+ if ((0, Option2.isSome)(data)) f(data.value);
405
+ return data;
406
+ };
407
+ Option2.filter = (predicate) => (data) => (0, Option2.isSome)(data) ? predicate(data.value) ? data : (0, Option2.none)() : data;
408
+ Option2.recover = (fallback) => (data) => (0, Option2.isSome)(data) ? data : fallback();
409
+ Option2.ap = (arg) => (data) => (0, Option2.isSome)(data) && (0, Option2.isSome)(arg) ? (0, Option2.some)(data.value(arg.value)) : (0, Option2.none)();
410
+ })(Option || (Option = {}));
411
+
412
+ // src/Core/Optional.ts
413
+ var Optional;
414
+ ((Optional2) => {
415
+ Optional2.make = (get2, set2) => ({ get: get2, set: set2 });
416
+ Optional2.prop = () => (key) => (0, Optional2.make)(
417
+ (s) => {
418
+ const val = s[key];
419
+ return val !== null && val !== void 0 ? Option.some(val) : Option.none();
420
+ },
421
+ (a) => (s) => ({ ...s, [key]: a })
422
+ );
423
+ Optional2.index = (i) => (0, Optional2.make)(
424
+ (arr) => i >= 0 && i < arr.length ? Option.some(arr[i]) : Option.none(),
425
+ (a) => (arr) => {
426
+ if (i < 0 || i >= arr.length) return arr;
427
+ const copy = [...arr];
428
+ copy[i] = a;
429
+ return copy;
430
+ }
431
+ );
432
+ Optional2.get = (opt) => (s) => opt.get(s);
433
+ Optional2.set = (opt) => (a) => (s) => opt.set(a)(s);
434
+ Optional2.modify = (opt) => (f) => (s) => {
435
+ const val = opt.get(s);
436
+ return val.kind === "None" ? s : opt.set(f(val.value))(s);
437
+ };
438
+ Optional2.getOrElse = (opt) => (defaultValue) => (s) => {
439
+ const val = opt.get(s);
440
+ return val.kind === "Some" ? val.value : defaultValue();
441
+ };
442
+ Optional2.fold = (opt) => (onNone, onSome) => (s) => {
443
+ const val = opt.get(s);
444
+ return val.kind === "Some" ? onSome(val.value) : onNone();
445
+ };
446
+ Optional2.match = (opt) => (cases) => (s) => {
447
+ const val = opt.get(s);
448
+ return val.kind === "Some" ? cases.some(val.value) : cases.none();
449
+ };
450
+ Optional2.andThen = (inner) => (outer) => (0, Optional2.make)(
451
+ (s) => {
452
+ const mid = outer.get(s);
453
+ return mid.kind === "None" ? Option.none() : inner.get(mid.value);
454
+ },
455
+ (b) => (s) => {
456
+ const mid = outer.get(s);
457
+ return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
458
+ }
459
+ );
460
+ Optional2.andThenLens = (inner) => (outer) => (0, Optional2.make)(
461
+ (s) => {
462
+ const mid = outer.get(s);
463
+ return mid.kind === "None" ? Option.none() : Option.some(inner.get(mid.value));
464
+ },
465
+ (b) => (s) => {
466
+ const mid = outer.get(s);
467
+ return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
468
+ }
469
+ );
470
+ })(Optional || (Optional = {}));
471
+
472
+ // src/Core/Predicate.ts
473
+ var Predicate;
474
+ ((Predicate2) => {
475
+ Predicate2.not = (p) => (a) => !p(a);
476
+ Predicate2.and = (second) => (first) => (a) => first(a) && second(a);
477
+ Predicate2.or = (second) => (first) => (a) => first(a) || second(a);
478
+ Predicate2.using = (f) => (p) => (b) => p(f(b));
479
+ Predicate2.all = (predicates) => (a) => predicates.every((p) => p(a));
480
+ Predicate2.any = (predicates) => (a) => predicates.some((p) => p(a));
481
+ Predicate2.fromRefinement = (r) => r;
482
+ })(Predicate || (Predicate = {}));
483
+
484
+ // src/Core/Reader.ts
485
+ var Reader;
486
+ ((Reader2) => {
487
+ Reader2.resolve = (value) => (_env) => value;
488
+ Reader2.ask = () => (env) => env;
489
+ Reader2.asks = (f) => (env) => f(env);
490
+ Reader2.map = (f) => (data) => (env) => f(data(env));
491
+ Reader2.chain = (f) => (data) => (env) => f(data(env))(env);
492
+ Reader2.ap = (arg) => (data) => (env) => data(env)(arg(env));
493
+ Reader2.tap = (f) => (data) => (env) => {
494
+ const a = data(env);
495
+ f(a);
496
+ return a;
497
+ };
498
+ Reader2.local = (f) => (data) => (env) => data(f(env));
499
+ Reader2.run = (env) => (data) => data(env);
500
+ })(Reader || (Reader = {}));
501
+
502
+ // src/Core/Refinement.ts
503
+ var Refinement;
504
+ ((Refinement2) => {
505
+ Refinement2.make = (f) => f;
506
+ Refinement2.compose = (bc) => (ab) => (a) => ab(a) && bc(a);
507
+ Refinement2.and = (second) => (first) => (a) => first(a) && second(a);
508
+ Refinement2.or = (second) => (first) => (a) => first(a) || second(a);
509
+ Refinement2.toFilter = (r) => (a) => r(a) ? Option.some(a) : Option.none();
510
+ Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.err(onFail(a));
511
+ })(Refinement || (Refinement = {}));
512
+
513
+ // src/Core/RemoteData.ts
514
+ var _notAsked = { kind: "NotAsked" };
515
+ var _loading = { kind: "Loading" };
516
+ var RemoteData;
517
+ ((RemoteData2) => {
518
+ RemoteData2.notAsked = () => _notAsked;
519
+ RemoteData2.loading = () => _loading;
520
+ RemoteData2.failure = (error) => ({
521
+ kind: "Failure",
522
+ error
523
+ });
524
+ RemoteData2.success = (value) => ({
525
+ kind: "Success",
526
+ value
527
+ });
528
+ RemoteData2.isNotAsked = (data) => data.kind === "NotAsked";
529
+ RemoteData2.isLoading = (data) => data.kind === "Loading";
530
+ RemoteData2.isFailure = (data) => data.kind === "Failure";
531
+ RemoteData2.isSuccess = (data) => data.kind === "Success";
532
+ RemoteData2.map = (f) => (data) => (0, RemoteData2.isSuccess)(data) ? (0, RemoteData2.success)(f(data.value)) : data;
533
+ RemoteData2.mapError = (f) => (data) => (0, RemoteData2.isFailure)(data) ? (0, RemoteData2.failure)(f(data.error)) : data;
534
+ RemoteData2.chain = (f) => (data) => (0, RemoteData2.isSuccess)(data) ? f(data.value) : data;
535
+ RemoteData2.ap = (arg) => (data) => {
536
+ if ((0, RemoteData2.isSuccess)(data) && (0, RemoteData2.isSuccess)(arg)) {
537
+ return (0, RemoteData2.success)(data.value(arg.value));
538
+ }
539
+ if ((0, RemoteData2.isFailure)(data)) return data;
540
+ if ((0, RemoteData2.isFailure)(arg)) return arg;
541
+ if ((0, RemoteData2.isLoading)(data) || (0, RemoteData2.isLoading)(arg)) return (0, RemoteData2.loading)();
542
+ return (0, RemoteData2.notAsked)();
543
+ };
544
+ RemoteData2.fold = (onNotAsked, onLoading, onFailure, onSuccess) => (data) => {
545
+ switch (data.kind) {
546
+ case "NotAsked":
547
+ return onNotAsked();
548
+ case "Loading":
549
+ return onLoading();
550
+ case "Failure":
551
+ return onFailure(data.error);
552
+ case "Success":
553
+ return onSuccess(data.value);
554
+ }
555
+ };
556
+ RemoteData2.match = (cases) => (data) => {
557
+ switch (data.kind) {
558
+ case "NotAsked":
559
+ return cases.notAsked();
560
+ case "Loading":
561
+ return cases.loading();
562
+ case "Failure":
563
+ return cases.failure(data.error);
564
+ case "Success":
565
+ return cases.success(data.value);
566
+ }
567
+ };
568
+ RemoteData2.getOrElse = (defaultValue) => (data) => (0, RemoteData2.isSuccess)(data) ? data.value : defaultValue();
569
+ RemoteData2.tap = (f) => (data) => {
570
+ if ((0, RemoteData2.isSuccess)(data)) f(data.value);
571
+ return data;
572
+ };
573
+ RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
574
+ RemoteData2.toOption = (data) => (0, RemoteData2.isSuccess)(data) ? Option.some(data.value) : Option.none();
575
+ RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
576
+ })(RemoteData || (RemoteData = {}));
577
+
578
+ // src/Core/Task.ts
579
+ var toPromise = (task) => Deferred.toPromise(task());
580
+ var Task;
581
+ ((Task2) => {
582
+ Task2.resolve = (value) => () => Deferred.fromPromise(Promise.resolve(value));
583
+ Task2.from = (f) => () => Deferred.fromPromise(f());
584
+ Task2.map = (f) => (data) => (0, Task2.from)(() => toPromise(data).then(f));
585
+ Task2.chain = (f) => (data) => (0, Task2.from)(() => toPromise(data).then((a) => toPromise(f(a))));
586
+ Task2.ap = (arg) => (data) => (0, Task2.from)(
587
+ () => Promise.all([
588
+ toPromise(data),
589
+ toPromise(arg)
590
+ ]).then(([f, a]) => f(a))
591
+ );
592
+ Task2.tap = (f) => (data) => (0, Task2.from)(
593
+ () => toPromise(data).then((a) => {
594
+ f(a);
595
+ return a;
596
+ })
597
+ );
598
+ Task2.all = (tasks) => (0, Task2.from)(
599
+ () => Promise.all(tasks.map((t) => toPromise(t)))
600
+ );
601
+ Task2.delay = (ms) => (data) => (0, Task2.from)(
602
+ () => new Promise(
603
+ (resolve2) => setTimeout(
604
+ () => toPromise(data).then(resolve2),
605
+ ms
606
+ )
607
+ )
608
+ );
609
+ Task2.repeat = (options) => (task) => (0, Task2.from)(() => {
610
+ const { times, delay: ms } = options;
611
+ if (times <= 0) return Promise.resolve([]);
612
+ const results = [];
613
+ const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
614
+ const run = (left) => toPromise(task).then((a) => {
615
+ results.push(a);
616
+ if (left <= 1) return results;
617
+ return wait().then(() => run(left - 1));
618
+ });
619
+ return run(times);
620
+ });
621
+ Task2.repeatUntil = (options) => (task) => (0, Task2.from)(() => {
622
+ const { when: predicate, delay: ms } = options;
623
+ const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
624
+ const run = () => toPromise(task).then((a) => {
625
+ if (predicate(a)) return a;
626
+ return wait().then(run);
627
+ });
628
+ return run();
629
+ });
630
+ Task2.race = (tasks) => (0, Task2.from)(() => Promise.race(tasks.map(toPromise)));
631
+ Task2.sequential = (tasks) => (0, Task2.from)(async () => {
632
+ const results = [];
633
+ for (const task of tasks) {
634
+ results.push(await toPromise(task));
635
+ }
636
+ return results;
637
+ });
638
+ Task2.timeout = (ms, onTimeout) => (task) => (0, Task2.from)(() => {
639
+ let timerId;
640
+ return Promise.race([
641
+ toPromise(task).then((a) => {
642
+ clearTimeout(timerId);
643
+ return Result.ok(a);
644
+ }),
645
+ new Promise((resolve2) => {
646
+ timerId = setTimeout(() => resolve2(Result.err(onTimeout())), ms);
647
+ })
648
+ ]);
649
+ });
650
+ })(Task || (Task = {}));
651
+
652
+ // src/Core/Resource.ts
653
+ var Resource;
654
+ ((Resource2) => {
655
+ Resource2.make = (acquire, release) => ({ acquire, release });
656
+ Resource2.fromTask = (acquire, release) => ({
657
+ acquire: Task.map((a) => Result.ok(a))(acquire),
658
+ release
659
+ });
660
+ Resource2.use = (f) => (resource) => Task.from(
661
+ () => Deferred.toPromise(resource.acquire()).then(async (acquired) => {
662
+ if (Result.isErr(acquired)) return acquired;
663
+ const a = acquired.value;
664
+ const usageResult = await Deferred.toPromise(f(a)());
665
+ await Deferred.toPromise(resource.release(a)());
666
+ return usageResult;
667
+ })
668
+ );
669
+ Resource2.combine = (resourceA, resourceB) => ({
670
+ acquire: Task.from(
671
+ () => Deferred.toPromise(resourceA.acquire()).then(async (acquiredA) => {
672
+ if (Result.isErr(acquiredA)) return acquiredA;
673
+ const a = acquiredA.value;
674
+ const acquiredB = await Deferred.toPromise(resourceB.acquire());
675
+ if (Result.isErr(acquiredB)) {
676
+ await Deferred.toPromise(resourceA.release(a)());
677
+ return acquiredB;
678
+ }
679
+ return Result.ok([a, acquiredB.value]);
680
+ })
681
+ ),
682
+ release: ([a, b]) => Task.from(() => Deferred.toPromise(resourceB.release(b)()).then(() => Deferred.toPromise(resourceA.release(a)())))
683
+ });
684
+ })(Resource || (Resource = {}));
685
+
686
+ // src/Core/State.ts
687
+ var State;
688
+ ((State2) => {
689
+ State2.resolve = (value) => (s) => [value, s];
690
+ State2.get = () => (s) => [s, s];
691
+ State2.gets = (f) => (s) => [f(s), s];
692
+ State2.put = (newState) => (_s) => [void 0, newState];
693
+ State2.modify = (f) => (s) => [void 0, f(s)];
694
+ State2.map = (f) => (st) => (s) => {
695
+ const [a, s1] = st(s);
696
+ return [f(a), s1];
697
+ };
698
+ State2.chain = (f) => (st) => (s) => {
699
+ const [a, s1] = st(s);
700
+ return f(a)(s1);
701
+ };
702
+ State2.ap = (arg) => (fn) => (s) => {
703
+ const [f, s1] = fn(s);
704
+ const [a, s2] = arg(s1);
705
+ return [f(a), s2];
706
+ };
707
+ State2.tap = (f) => (st) => (s) => {
708
+ const [a, s1] = st(s);
709
+ f(a);
710
+ return [a, s1];
711
+ };
712
+ State2.run = (initialState) => (st) => st(initialState);
713
+ State2.evaluate = (initialState) => (st) => st(initialState)[0];
714
+ State2.execute = (initialState) => (st) => st(initialState)[1];
715
+ })(State || (State = {}));
716
+
717
+ // src/Core/TaskOption.ts
718
+ var TaskOption;
719
+ ((TaskOption2) => {
720
+ TaskOption2.some = (value) => Task.resolve(Option.some(value));
721
+ TaskOption2.none = () => Task.resolve(Option.none());
722
+ TaskOption2.fromOption = (option) => Task.resolve(option);
723
+ TaskOption2.fromTask = (task) => Task.map(Option.some)(task);
724
+ TaskOption2.tryCatch = (f) => Task.from(
725
+ () => f().then(Option.some).catch(() => Option.none())
726
+ );
727
+ TaskOption2.map = (f) => (data) => Task.map(Option.map(f))(data);
728
+ TaskOption2.chain = (f) => (data) => Task.chain((option) => Option.isSome(option) ? f(option.value) : Task.resolve(Option.none()))(data);
729
+ TaskOption2.ap = (arg) => (data) => Task.from(
730
+ () => Promise.all([
731
+ Deferred.toPromise(data()),
732
+ Deferred.toPromise(arg())
733
+ ]).then(([of_, oa]) => Option.ap(oa)(of_))
734
+ );
735
+ TaskOption2.fold = (onNone, onSome) => (data) => Task.map(Option.fold(onNone, onSome))(data);
736
+ TaskOption2.match = (cases) => (data) => Task.map(Option.match(cases))(data);
737
+ TaskOption2.getOrElse = (defaultValue) => (data) => Task.map(Option.getOrElse(defaultValue))(data);
738
+ TaskOption2.tap = (f) => (data) => Task.map(Option.tap(f))(data);
739
+ TaskOption2.filter = (predicate) => (data) => Task.map(Option.filter(predicate))(data);
740
+ TaskOption2.toTaskResult = (onNone) => (data) => Task.map(Option.toResult(onNone))(data);
741
+ })(TaskOption || (TaskOption = {}));
742
+
743
+ // src/Core/TaskResult.ts
744
+ var TaskResult;
745
+ ((TaskResult2) => {
746
+ TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
747
+ TaskResult2.err = (error) => Task.resolve(Result.err(error));
748
+ TaskResult2.tryCatch = (f, onError) => Task.from(
749
+ () => f().then(Result.ok).catch((e) => Result.err(onError(e)))
750
+ );
751
+ TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
752
+ TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
753
+ TaskResult2.chain = (f) => (data) => Task.chain((result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.err(result.error)))(
754
+ data
755
+ );
756
+ TaskResult2.fold = (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data);
757
+ TaskResult2.match = (cases) => (data) => Task.map(Result.match(cases))(data);
758
+ TaskResult2.recover = (fallback) => (data) => Task.chain(
759
+ (result) => Result.isErr(result) ? fallback(result.error) : Task.resolve(result)
760
+ )(data);
761
+ TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
762
+ TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
763
+ TaskResult2.retry = (options) => (data) => Task.from(() => {
764
+ const { attempts, backoff, when: shouldRetry } = options;
765
+ const getDelay = (n) => backoff === void 0 ? 0 : typeof backoff === "function" ? backoff(n) : backoff;
766
+ const run = (left) => Deferred.toPromise(data()).then((result) => {
767
+ if (Result.isOk(result)) return result;
768
+ if (left <= 1) return result;
769
+ if (shouldRetry !== void 0 && !shouldRetry(result.error)) {
770
+ return result;
771
+ }
772
+ const ms = getDelay(attempts - left + 1);
773
+ return (ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve()).then(() => run(left - 1));
774
+ });
775
+ return run(attempts);
776
+ });
777
+ TaskResult2.timeout = (ms, onTimeout) => (data) => Task.from(() => {
778
+ let timerId;
779
+ return Promise.race([
780
+ Deferred.toPromise(data()).then((result) => {
781
+ clearTimeout(timerId);
782
+ return result;
783
+ }),
784
+ new Promise((resolve) => {
785
+ timerId = setTimeout(() => resolve(Result.err(onTimeout())), ms);
786
+ })
787
+ ]);
788
+ });
789
+ })(TaskResult || (TaskResult = {}));
790
+
791
+ // src/Core/Validation.ts
792
+ var Validation;
793
+ ((Validation2) => {
794
+ Validation2.valid = (value) => ({
795
+ kind: "Valid",
796
+ value
797
+ });
798
+ Validation2.invalid = (error) => ({
799
+ kind: "Invalid",
800
+ errors: [error]
801
+ });
802
+ Validation2.invalidAll = (errors) => ({
803
+ kind: "Invalid",
804
+ errors
805
+ });
806
+ Validation2.isValid = (data) => data.kind === "Valid";
807
+ Validation2.isInvalid = (data) => data.kind === "Invalid";
808
+ Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
809
+ Validation2.ap = (arg) => (data) => {
810
+ if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
811
+ const errors = [
812
+ ...(0, Validation2.isInvalid)(data) ? data.errors : [],
813
+ ...(0, Validation2.isInvalid)(arg) ? arg.errors : []
814
+ ];
815
+ return (0, Validation2.invalidAll)(errors);
816
+ };
817
+ Validation2.fold = (onInvalid, onValid) => (data) => (0, Validation2.isValid)(data) ? onValid(data.value) : onInvalid(data.errors);
818
+ Validation2.match = (cases) => (data) => (0, Validation2.isValid)(data) ? cases.valid(data.value) : cases.invalid(data.errors);
819
+ Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isValid)(data) ? data.value : defaultValue();
820
+ Validation2.tap = (f) => (data) => {
821
+ if ((0, Validation2.isValid)(data)) f(data.value);
822
+ return data;
823
+ };
824
+ Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
825
+ Validation2.recoverUnless = (blockedErrors, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some((err) => blockedErrors.includes(err)) ? fallback() : data;
826
+ Validation2.product = (first, second) => {
827
+ if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
828
+ const errors = [
829
+ ...(0, Validation2.isInvalid)(first) ? first.errors : [],
830
+ ...(0, Validation2.isInvalid)(second) ? second.errors : []
831
+ ];
832
+ return (0, Validation2.invalidAll)(errors);
833
+ };
834
+ Validation2.productAll = (data) => {
835
+ const values = [];
836
+ const errors = [];
837
+ for (const v of data) {
838
+ if ((0, Validation2.isValid)(v)) values.push(v.value);
839
+ else errors.push(...v.errors);
840
+ }
841
+ return errors.length > 0 ? (0, Validation2.invalidAll)(errors) : (0, Validation2.valid)(values);
842
+ };
843
+ })(Validation || (Validation = {}));
844
+
845
+ // src/Core/TaskValidation.ts
846
+ var TaskValidation;
847
+ ((TaskValidation2) => {
848
+ TaskValidation2.valid = (value) => Task.resolve(Validation.valid(value));
849
+ TaskValidation2.invalid = (error) => Task.resolve(Validation.invalid(error));
850
+ TaskValidation2.invalidAll = (errors) => Task.resolve(Validation.invalidAll(errors));
851
+ TaskValidation2.fromValidation = (validation) => Task.resolve(validation);
852
+ TaskValidation2.tryCatch = (f, onError) => Task.from(
853
+ () => f().then(Validation.valid).catch((e) => Validation.invalid(onError(e)))
854
+ );
855
+ TaskValidation2.map = (f) => (data) => Task.map(Validation.map(f))(data);
856
+ TaskValidation2.ap = (arg) => (data) => Task.from(
857
+ () => Promise.all([
858
+ Deferred.toPromise(data()),
859
+ Deferred.toPromise(arg())
860
+ ]).then(([vf, va]) => Validation.ap(va)(vf))
861
+ );
862
+ TaskValidation2.fold = (onInvalid, onValid) => (data) => Task.map(Validation.fold(onInvalid, onValid))(data);
863
+ TaskValidation2.match = (cases) => (data) => Task.map(Validation.match(cases))(data);
864
+ TaskValidation2.getOrElse = (defaultValue) => (data) => Task.map(Validation.getOrElse(defaultValue))(data);
865
+ TaskValidation2.tap = (f) => (data) => Task.map(Validation.tap(f))(data);
866
+ TaskValidation2.recover = (fallback) => (data) => Task.chain(
867
+ (validation) => Validation.isValid(validation) ? Task.resolve(validation) : fallback(validation.errors)
868
+ )(data);
869
+ TaskValidation2.product = (first, second) => Task.from(
870
+ () => Promise.all([
871
+ Deferred.toPromise(first()),
872
+ Deferred.toPromise(second())
873
+ ]).then(([va, vb]) => Validation.product(va, vb))
874
+ );
875
+ TaskValidation2.productAll = (data) => Task.from(
876
+ () => Promise.all(data.map((t) => Deferred.toPromise(t()))).then((results) => Validation.productAll(results))
877
+ );
878
+ })(TaskValidation || (TaskValidation = {}));
879
+
880
+ // src/Core/These.ts
881
+ var These;
882
+ ((These2) => {
883
+ These2.first = (value) => ({ kind: "First", first: value });
884
+ These2.second = (value) => ({ kind: "Second", second: value });
885
+ These2.both = (first2, second2) => ({
886
+ kind: "Both",
887
+ first: first2,
888
+ second: second2
889
+ });
890
+ These2.isFirst = (data) => data.kind === "First";
891
+ These2.isSecond = (data) => data.kind === "Second";
892
+ These2.isBoth = (data) => data.kind === "Both";
893
+ These2.hasFirst = (data) => data.kind === "First" || data.kind === "Both";
894
+ These2.hasSecond = (data) => data.kind === "Second" || data.kind === "Both";
895
+ These2.mapFirst = (f) => (data) => {
896
+ if ((0, These2.isSecond)(data)) return data;
897
+ if ((0, These2.isFirst)(data)) return (0, These2.first)(f(data.first));
898
+ return (0, These2.both)(f(data.first), data.second);
899
+ };
900
+ These2.mapSecond = (f) => (data) => {
901
+ if ((0, These2.isFirst)(data)) return data;
902
+ if ((0, These2.isSecond)(data)) return (0, These2.second)(f(data.second));
903
+ return (0, These2.both)(data.first, f(data.second));
904
+ };
905
+ These2.mapBoth = (onFirst, onSecond) => (data) => {
906
+ if ((0, These2.isSecond)(data)) return (0, These2.second)(onSecond(data.second));
907
+ if ((0, These2.isFirst)(data)) return (0, These2.first)(onFirst(data.first));
908
+ return (0, These2.both)(onFirst(data.first), onSecond(data.second));
909
+ };
910
+ These2.chainFirst = (f) => (data) => {
911
+ if ((0, These2.isSecond)(data)) return data;
912
+ return f(data.first);
913
+ };
914
+ These2.chainSecond = (f) => (data) => {
915
+ if ((0, These2.isFirst)(data)) return data;
916
+ return f(data.second);
917
+ };
918
+ These2.fold = (onFirst, onSecond, onBoth) => (data) => {
919
+ if ((0, These2.isSecond)(data)) return onSecond(data.second);
920
+ if ((0, These2.isFirst)(data)) return onFirst(data.first);
921
+ return onBoth(data.first, data.second);
922
+ };
923
+ These2.match = (cases) => (data) => {
924
+ if ((0, These2.isSecond)(data)) return cases.second(data.second);
925
+ if ((0, These2.isFirst)(data)) return cases.first(data.first);
926
+ return cases.both(data.first, data.second);
927
+ };
928
+ These2.getFirstOrElse = (defaultValue) => (data) => (0, These2.hasFirst)(data) ? data.first : defaultValue();
929
+ These2.getSecondOrElse = (defaultValue) => (data) => (0, These2.hasSecond)(data) ? data.second : defaultValue();
930
+ These2.tap = (f) => (data) => {
931
+ if ((0, These2.hasFirst)(data)) f(data.first);
932
+ return data;
933
+ };
934
+ These2.swap = (data) => {
935
+ if ((0, These2.isSecond)(data)) return (0, These2.first)(data.second);
936
+ if ((0, These2.isFirst)(data)) return (0, These2.second)(data.first);
937
+ return (0, These2.both)(data.second, data.first);
938
+ };
939
+ })(These || (These = {}));
940
+
941
+ // src/Core/Tuple.ts
942
+ var Tuple;
943
+ ((Tuple2) => {
944
+ Tuple2.make = (first2, second2) => [first2, second2];
945
+ Tuple2.first = (tuple) => tuple[0];
946
+ Tuple2.second = (tuple) => tuple[1];
947
+ Tuple2.mapFirst = (f) => (tuple) => [f(tuple[0]), tuple[1]];
948
+ Tuple2.mapSecond = (f) => (tuple) => [tuple[0], f(tuple[1])];
949
+ Tuple2.mapBoth = (onFirst, onSecond) => (tuple) => [
950
+ onFirst(tuple[0]),
951
+ onSecond(tuple[1])
952
+ ];
953
+ Tuple2.fold = (f) => (tuple) => f(tuple[0], tuple[1]);
954
+ Tuple2.swap = (tuple) => [tuple[1], tuple[0]];
955
+ Tuple2.toArray = (tuple) => [...tuple];
956
+ Tuple2.tap = (f) => (tuple) => {
957
+ f(tuple[0], tuple[1]);
958
+ return tuple;
959
+ };
960
+ })(Tuple || (Tuple = {}));
961
+
962
+ // src/Types/Brand.ts
963
+ var Brand;
964
+ ((Brand2) => {
965
+ Brand2.wrap = () => (value) => value;
966
+ Brand2.unwrap = (branded) => branded;
967
+ })(Brand || (Brand = {}));
968
+
969
+ // src/Types/NonEmptyList.ts
970
+ var isNonEmptyList = (list) => list.length > 0;
971
+
972
+ // src/Utils/Arr.ts
973
+ var Arr;
974
+ ((Arr2) => {
975
+ Arr2.head = (data) => data.length > 0 ? Option.some(data[0]) : Option.none();
976
+ Arr2.last = (data) => data.length > 0 ? Option.some(data[data.length - 1]) : Option.none();
977
+ Arr2.tail = (data) => data.length > 0 ? Option.some(data.slice(1)) : Option.none();
978
+ Arr2.init = (data) => data.length > 0 ? Option.some(data.slice(0, -1)) : Option.none();
979
+ Arr2.findFirst = (predicate) => (data) => {
980
+ const idx = data.findIndex(predicate);
981
+ return idx >= 0 ? Option.some(data[idx]) : Option.none();
982
+ };
983
+ Arr2.findLast = (predicate) => (data) => {
984
+ for (let i = data.length - 1; i >= 0; i--) {
985
+ if (predicate(data[i])) return Option.some(data[i]);
986
+ }
987
+ return Option.none();
988
+ };
989
+ Arr2.findIndex = (predicate) => (data) => {
990
+ const idx = data.findIndex(predicate);
991
+ return idx >= 0 ? Option.some(idx) : Option.none();
992
+ };
993
+ Arr2.map = (f) => (data) => {
994
+ const n = data.length;
995
+ const result = new Array(n);
996
+ for (let i = 0; i < n; i++) result[i] = f(data[i]);
997
+ return result;
998
+ };
999
+ Arr2.filter = (predicate) => (data) => {
1000
+ const n = data.length;
1001
+ const result = [];
1002
+ for (let i = 0; i < n; i++) {
1003
+ if (predicate(data[i])) result.push(data[i]);
1004
+ }
1005
+ return result;
1006
+ };
1007
+ Arr2.partition = (predicate) => (data) => {
1008
+ const pass = [];
1009
+ const fail = [];
1010
+ for (const a of data) {
1011
+ (predicate(a) ? pass : fail).push(a);
1012
+ }
1013
+ return [pass, fail];
1014
+ };
1015
+ Arr2.groupBy = (f) => (data) => {
1016
+ const result = {};
1017
+ for (const a of data) {
1018
+ const key = f(a);
1019
+ if (!result[key]) result[key] = [];
1020
+ result[key].push(a);
1021
+ }
1022
+ return result;
1023
+ };
1024
+ Arr2.uniq = (data) => [
1025
+ ...new Set(data)
1026
+ ];
1027
+ Arr2.uniqBy = (f) => (data) => {
1028
+ const seen = /* @__PURE__ */ new Set();
1029
+ const result = [];
1030
+ for (const a of data) {
1031
+ const key = f(a);
1032
+ if (!seen.has(key)) {
1033
+ seen.add(key);
1034
+ result.push(a);
1035
+ }
1036
+ }
1037
+ return result;
1038
+ };
1039
+ Arr2.sortBy = (compare) => (data) => [...data].sort(compare);
1040
+ Arr2.zip = (other) => (data) => {
1041
+ const len = Math.min(data.length, other.length);
1042
+ const result = new Array(len);
1043
+ for (let i = 0; i < len; i++) {
1044
+ result[i] = [data[i], other[i]];
1045
+ }
1046
+ return result;
1047
+ };
1048
+ Arr2.zipWith = (f) => (other) => (data) => {
1049
+ const len = Math.min(data.length, other.length);
1050
+ const result = new Array(len);
1051
+ for (let i = 0; i < len; i++) {
1052
+ result[i] = f(data[i], other[i]);
1053
+ }
1054
+ return result;
1055
+ };
1056
+ Arr2.intersperse = (sep) => (data) => {
1057
+ if (data.length <= 1) return data;
1058
+ const result = [data[0]];
1059
+ for (let i = 1; i < data.length; i++) {
1060
+ result.push(sep, data[i]);
1061
+ }
1062
+ return result;
1063
+ };
1064
+ Arr2.chunksOf = (n) => (data) => {
1065
+ if (n <= 0) return [];
1066
+ const result = [];
1067
+ for (let i = 0; i < data.length; i += n) {
1068
+ result.push(data.slice(i, i + n));
1069
+ }
1070
+ return result;
1071
+ };
1072
+ Arr2.flatten = (data) => [].concat(...data);
1073
+ Arr2.flatMap = (f) => (data) => {
1074
+ const n = data.length;
1075
+ const result = [];
1076
+ for (let i = 0; i < n; i++) {
1077
+ const chunk = f(data[i]);
1078
+ const m = chunk.length;
1079
+ for (let j = 0; j < m; j++) result.push(chunk[j]);
1080
+ }
1081
+ return result;
1082
+ };
1083
+ Arr2.reduce = (initial, f) => (data) => data.reduce(f, initial);
1084
+ Arr2.traverse = (f) => (data) => {
1085
+ const n = data.length;
1086
+ const result = new Array(n);
1087
+ for (let i = 0; i < n; i++) {
1088
+ const mapped = f(data[i]);
1089
+ if (mapped.kind === "None") return Option.none();
1090
+ result[i] = mapped.value;
1091
+ }
1092
+ return Option.some(result);
1093
+ };
1094
+ Arr2.traverseResult = (f) => (data) => {
1095
+ const n = data.length;
1096
+ const result = new Array(n);
1097
+ for (let i = 0; i < n; i++) {
1098
+ const mapped = f(data[i]);
1099
+ if (mapped.kind === "Error") return mapped;
1100
+ result[i] = mapped.value;
1101
+ }
1102
+ return Result.ok(result);
1103
+ };
1104
+ Arr2.traverseTask = (f) => (data) => Task.from(() => Promise.all(data.map((a) => Deferred.toPromise(f(a)()))));
1105
+ Arr2.sequence = (data) => (0, Arr2.traverse)((a) => a)(data);
1106
+ Arr2.sequenceResult = (data) => (0, Arr2.traverseResult)((a) => a)(data);
1107
+ Arr2.sequenceTask = (data) => (0, Arr2.traverseTask)((a) => a)(data);
1108
+ Arr2.traverseTaskResult = (f) => (data) => Task.from(async () => {
1109
+ const result = [];
1110
+ for (const a of data) {
1111
+ const r = await Deferred.toPromise(f(a)());
1112
+ if (Result.isErr(r)) return r;
1113
+ result.push(r.value);
1114
+ }
1115
+ return Result.ok(result);
1116
+ });
1117
+ Arr2.sequenceTaskResult = (data) => (0, Arr2.traverseTaskResult)((a) => a)(data);
1118
+ Arr2.isNonEmpty = (data) => isNonEmptyList(data);
1119
+ Arr2.size = (data) => data.length;
1120
+ Arr2.some = (predicate) => (data) => {
1121
+ const n = data.length;
1122
+ for (let i = 0; i < n; i++) if (predicate(data[i])) return true;
1123
+ return false;
1124
+ };
1125
+ Arr2.every = (predicate) => (data) => {
1126
+ const n = data.length;
1127
+ for (let i = 0; i < n; i++) if (!predicate(data[i])) return false;
1128
+ return true;
1129
+ };
1130
+ Arr2.reverse = (data) => [...data].reverse();
1131
+ Arr2.take = (n) => (data) => n <= 0 ? [] : data.slice(0, n);
1132
+ Arr2.drop = (n) => (data) => data.slice(n);
1133
+ Arr2.takeWhile = (predicate) => (data) => {
1134
+ const result = [];
1135
+ for (const a of data) {
1136
+ if (!predicate(a)) break;
1137
+ result.push(a);
1138
+ }
1139
+ return result;
1140
+ };
1141
+ Arr2.dropWhile = (predicate) => (data) => {
1142
+ let i = 0;
1143
+ while (i < data.length && predicate(data[i])) i++;
1144
+ return data.slice(i);
1145
+ };
1146
+ Arr2.scan = (initial, f) => (data) => {
1147
+ const n = data.length;
1148
+ const result = new Array(n);
1149
+ let acc = initial;
1150
+ for (let i = 0; i < n; i++) {
1151
+ acc = f(acc, data[i]);
1152
+ result[i] = acc;
1153
+ }
1154
+ return result;
1155
+ };
1156
+ Arr2.splitAt = (index) => (data) => {
1157
+ const i = Math.max(0, index);
1158
+ return [data.slice(0, i), data.slice(i)];
1159
+ };
1160
+ })(Arr || (Arr = {}));
1161
+
1162
+ // src/Utils/Dict.ts
1163
+ var Dict;
1164
+ ((Dict2) => {
1165
+ Dict2.empty = () => new globalThis.Map();
1166
+ Dict2.singleton = (key, value) => new globalThis.Map([[key, value]]);
1167
+ Dict2.fromEntries = (entries2) => new globalThis.Map(entries2);
1168
+ Dict2.fromRecord = (rec) => new globalThis.Map(Object.entries(rec));
1169
+ Dict2.groupBy = (keyFn) => (items) => {
1170
+ const result = new globalThis.Map();
1171
+ for (const item of items) {
1172
+ const key = keyFn(item);
1173
+ const arr = result.get(key);
1174
+ if (arr !== void 0) arr.push(item);
1175
+ else result.set(key, [item]);
1176
+ }
1177
+ return result;
1178
+ };
1179
+ Dict2.has = (key) => (m) => m.has(key);
1180
+ Dict2.lookup = (key) => (m) => m.has(key) ? Option.some(m.get(key)) : Option.none();
1181
+ Dict2.size = (m) => m.size;
1182
+ Dict2.isEmpty = (m) => m.size === 0;
1183
+ Dict2.keys = (m) => [...m.keys()];
1184
+ Dict2.values = (m) => [...m.values()];
1185
+ Dict2.entries = (m) => [...m.entries()];
1186
+ Dict2.insert = (key, value) => (m) => {
1187
+ const result = new globalThis.Map(m);
1188
+ result.set(key, value);
1189
+ return result;
1190
+ };
1191
+ Dict2.remove = (key) => (m) => {
1192
+ if (!m.has(key)) return m;
1193
+ const result = new globalThis.Map(m);
1194
+ result.delete(key);
1195
+ return result;
1196
+ };
1197
+ Dict2.upsert = (key, f) => (m) => {
1198
+ const result = new globalThis.Map(m);
1199
+ result.set(key, f((0, Dict2.lookup)(key)(m)));
1200
+ return result;
1201
+ };
1202
+ Dict2.map = (f) => (m) => {
1203
+ const result = new globalThis.Map();
1204
+ for (const [k, v] of m) {
1205
+ result.set(k, f(v));
1206
+ }
1207
+ return result;
1208
+ };
1209
+ Dict2.mapWithKey = (f) => (m) => {
1210
+ const result = new globalThis.Map();
1211
+ for (const [k, v] of m) {
1212
+ result.set(k, f(k, v));
1213
+ }
1214
+ return result;
1215
+ };
1216
+ Dict2.filter = (predicate) => (m) => {
1217
+ const result = new globalThis.Map();
1218
+ for (const [k, v] of m) {
1219
+ if (predicate(v)) result.set(k, v);
1220
+ }
1221
+ return result;
1222
+ };
1223
+ Dict2.filterWithKey = (predicate) => (m) => {
1224
+ const result = new globalThis.Map();
1225
+ for (const [k, v] of m) {
1226
+ if (predicate(k, v)) result.set(k, v);
1227
+ }
1228
+ return result;
1229
+ };
1230
+ Dict2.compact = (m) => {
1231
+ const result = new globalThis.Map();
1232
+ for (const [k, v] of m) {
1233
+ if (v.kind === "Some") result.set(k, v.value);
1234
+ }
1235
+ return result;
1236
+ };
1237
+ Dict2.union = (other) => (m) => {
1238
+ const result = new globalThis.Map(m);
1239
+ for (const [k, v] of other) {
1240
+ result.set(k, v);
1241
+ }
1242
+ return result;
1243
+ };
1244
+ Dict2.intersection = (other) => (m) => {
1245
+ const result = new globalThis.Map();
1246
+ for (const [k, v] of m) {
1247
+ if (other.has(k)) result.set(k, v);
1248
+ }
1249
+ return result;
1250
+ };
1251
+ Dict2.difference = (other) => (m) => {
1252
+ const result = new globalThis.Map();
1253
+ for (const [k, v] of m) {
1254
+ if (!other.has(k)) result.set(k, v);
1255
+ }
1256
+ return result;
1257
+ };
1258
+ Dict2.reduce = (init, f) => (m) => {
1259
+ let acc = init;
1260
+ for (const v of m.values()) {
1261
+ acc = f(acc, v);
1262
+ }
1263
+ return acc;
1264
+ };
1265
+ Dict2.reduceWithKey = (init, f) => (m) => {
1266
+ let acc = init;
1267
+ for (const [k, v] of m) {
1268
+ acc = f(acc, v, k);
1269
+ }
1270
+ return acc;
1271
+ };
1272
+ Dict2.toRecord = (m) => Object.fromEntries(m);
1273
+ })(Dict || (Dict = {}));
1274
+
1275
+ // src/Utils/Num.ts
1276
+ var Num;
1277
+ ((Num2) => {
1278
+ Num2.range = (from, to, step = 1) => {
1279
+ if (step <= 0 || from > to) return [];
1280
+ const count = Math.floor((to - from) / step) + 1;
1281
+ const result = new Array(count);
1282
+ for (let i = 0; i < count; i++) {
1283
+ result[i] = from + i * step;
1284
+ }
1285
+ return result;
1286
+ };
1287
+ Num2.clamp = (min, max) => (n) => Math.min(Math.max(n, min), max);
1288
+ Num2.between = (min, max) => (n) => n >= min && n <= max;
1289
+ Num2.parse = (s) => {
1290
+ if (s.trim() === "") return Option.none();
1291
+ const n = Number(s);
1292
+ return isNaN(n) ? Option.none() : Option.some(n);
1293
+ };
1294
+ Num2.add = (b) => (a) => a + b;
1295
+ Num2.subtract = (b) => (a) => a - b;
1296
+ Num2.multiply = (b) => (a) => a * b;
1297
+ Num2.divide = (b) => (a) => a / b;
1298
+ })(Num || (Num = {}));
1299
+
1300
+ // src/Utils/Rec.ts
1301
+ var Rec;
1302
+ ((Rec2) => {
1303
+ Rec2.map = (f) => (data) => {
1304
+ const keys2 = Object.keys(data);
1305
+ const vals = Object.values(data);
1306
+ const result = {};
1307
+ for (let i = 0; i < keys2.length; i++) {
1308
+ result[keys2[i]] = f(vals[i]);
1309
+ }
1310
+ return result;
1311
+ };
1312
+ Rec2.mapWithKey = (f) => (data) => {
1313
+ const keys2 = Object.keys(data);
1314
+ const vals = Object.values(data);
1315
+ const result = {};
1316
+ for (let i = 0; i < keys2.length; i++) {
1317
+ result[keys2[i]] = f(keys2[i], vals[i]);
1318
+ }
1319
+ return result;
1320
+ };
1321
+ Rec2.filter = (predicate) => (data) => {
1322
+ const result = {};
1323
+ for (const [k, v] of Object.entries(data)) {
1324
+ if (predicate(v)) result[k] = v;
1325
+ }
1326
+ return result;
1327
+ };
1328
+ Rec2.filterWithKey = (predicate) => (data) => {
1329
+ const result = {};
1330
+ for (const [k, v] of Object.entries(data)) {
1331
+ if (predicate(k, v)) result[k] = v;
1332
+ }
1333
+ return result;
1334
+ };
1335
+ Rec2.lookup = (key) => (data) => Object.hasOwn(data, key) ? Option.some(data[key]) : Option.none();
1336
+ Rec2.keys = (data) => Object.keys(data);
1337
+ Rec2.values = (data) => Object.values(data);
1338
+ Rec2.entries = (data) => Object.entries(data);
1339
+ Rec2.fromEntries = (data) => Object.fromEntries(data);
1340
+ Rec2.groupBy = (keyFn) => (items) => {
1341
+ const result = {};
1342
+ for (const item of items) {
1343
+ const key = keyFn(item);
1344
+ if (key in result) result[key].push(item);
1345
+ else result[key] = [item];
1346
+ }
1347
+ return result;
1348
+ };
1349
+ Rec2.pick = (...pickedKeys) => (data) => {
1350
+ const result = {};
1351
+ for (const key of pickedKeys) {
1352
+ if (Object.hasOwn(data, key)) {
1353
+ result[key] = data[key];
1354
+ }
1355
+ }
1356
+ return result;
1357
+ };
1358
+ Rec2.omit = (...omittedKeys) => (data) => {
1359
+ const omitSet = new Set(omittedKeys);
1360
+ const result = {};
1361
+ for (const key of Object.keys(data)) {
1362
+ if (!omitSet.has(key)) {
1363
+ result[key] = data[key];
1364
+ }
1365
+ }
1366
+ return result;
1367
+ };
1368
+ Rec2.merge = (other) => (data) => ({
1369
+ ...data,
1370
+ ...other
1371
+ });
1372
+ Rec2.isEmpty = (data) => Object.keys(data).length === 0;
1373
+ Rec2.size = (data) => Object.keys(data).length;
1374
+ Rec2.mapKeys = (f) => (data) => {
1375
+ const result = {};
1376
+ for (const [k, v] of Object.entries(data)) {
1377
+ result[f(k)] = v;
1378
+ }
1379
+ return result;
1380
+ };
1381
+ Rec2.compact = (data) => {
1382
+ const result = {};
1383
+ for (const [k, v] of Object.entries(data)) {
1384
+ if (v.kind === "Some") result[k] = v.value;
1385
+ }
1386
+ return result;
1387
+ };
1388
+ })(Rec || (Rec = {}));
1389
+
1390
+ // src/Utils/Str.ts
1391
+ var Str;
1392
+ ((Str2) => {
1393
+ Str2.split = (separator) => (s) => s.split(separator);
1394
+ Str2.trim = (s) => s.trim();
1395
+ Str2.includes = (substring) => (s) => s.includes(substring);
1396
+ Str2.startsWith = (prefix) => (s) => s.startsWith(prefix);
1397
+ Str2.endsWith = (suffix) => (s) => s.endsWith(suffix);
1398
+ Str2.toUpperCase = (s) => s.toUpperCase();
1399
+ Str2.toLowerCase = (s) => s.toLowerCase();
1400
+ Str2.lines = (s) => s.split(/\r?\n|\r/);
1401
+ Str2.words = (s) => s.trim().split(/\s+/).filter(Boolean);
1402
+ Str2.parse = {
1403
+ /**
1404
+ * Parses a string as an integer (base 10). Returns `None` if the result is `NaN`.
1405
+ *
1406
+ * @example
1407
+ * ```ts
1408
+ * Str.parse.int("42"); // Some(42)
1409
+ * Str.parse.int("3.7"); // Some(3)
1410
+ * Str.parse.int("abc"); // None
1411
+ * ```
1412
+ */
1413
+ int: (s) => {
1414
+ const n = parseInt(s, 10);
1415
+ return isNaN(n) ? Option.none() : Option.some(n);
1416
+ },
1417
+ /**
1418
+ * Parses a string as a floating-point number. Returns `None` if the result is `NaN`.
1419
+ *
1420
+ * @example
1421
+ * ```ts
1422
+ * Str.parse.float("3.14"); // Some(3.14)
1423
+ * Str.parse.float("42"); // Some(42)
1424
+ * Str.parse.float("abc"); // None
1425
+ * ```
1426
+ */
1427
+ float: (s) => {
1428
+ const n = parseFloat(s);
1429
+ return isNaN(n) ? Option.none() : Option.some(n);
1430
+ }
1431
+ };
1432
+ })(Str || (Str = {}));
1433
+
1434
+ // src/Utils/Uniq.ts
1435
+ var Uniq;
1436
+ ((Uniq2) => {
1437
+ Uniq2.empty = () => new globalThis.Set();
1438
+ Uniq2.singleton = (item) => new globalThis.Set([item]);
1439
+ Uniq2.fromArray = (arr) => new globalThis.Set(arr);
1440
+ Uniq2.has = (item) => (s) => s.has(item);
1441
+ Uniq2.size = (s) => s.size;
1442
+ Uniq2.isEmpty = (s) => s.size === 0;
1443
+ Uniq2.isSubsetOf = (other) => (s) => {
1444
+ const set = s;
1445
+ if (typeof set.isSubsetOf === "function") return set.isSubsetOf(other);
1446
+ for (const item of s) {
1447
+ if (!other.has(item)) return false;
1448
+ }
1449
+ return true;
1450
+ };
1451
+ Uniq2.insert = (item) => (s) => {
1452
+ if (s.has(item)) return s;
1453
+ const result = new globalThis.Set(s);
1454
+ result.add(item);
1455
+ return result;
1456
+ };
1457
+ Uniq2.remove = (item) => (s) => {
1458
+ if (!s.has(item)) return s;
1459
+ const result = new globalThis.Set(s);
1460
+ result.delete(item);
1461
+ return result;
1462
+ };
1463
+ Uniq2.map = (f) => (s) => {
1464
+ const result = new globalThis.Set();
1465
+ for (const item of s) {
1466
+ result.add(f(item));
1467
+ }
1468
+ return result;
1469
+ };
1470
+ Uniq2.filter = (predicate) => (s) => {
1471
+ const result = new globalThis.Set();
1472
+ for (const item of s) {
1473
+ if (predicate(item)) result.add(item);
1474
+ }
1475
+ return result;
1476
+ };
1477
+ Uniq2.union = (other) => (s) => {
1478
+ const set = s;
1479
+ if (typeof set.union === "function") return set.union(other);
1480
+ const result = new globalThis.Set(s);
1481
+ for (const item of other) result.add(item);
1482
+ return result;
1483
+ };
1484
+ Uniq2.intersection = (other) => (s) => {
1485
+ const set = s;
1486
+ if (typeof set.intersection === "function") return set.intersection(other);
1487
+ const result = new globalThis.Set();
1488
+ for (const item of s) if (other.has(item)) result.add(item);
1489
+ return result;
1490
+ };
1491
+ Uniq2.difference = (other) => (s) => {
1492
+ const set = s;
1493
+ if (typeof set.difference === "function") return set.difference(other);
1494
+ const result = new globalThis.Set();
1495
+ for (const item of s) if (!other.has(item)) result.add(item);
1496
+ return result;
1497
+ };
1498
+ Uniq2.reduce = (init, f) => (s) => {
1499
+ let acc = init;
1500
+ for (const item of s) {
1501
+ acc = f(acc, item);
1502
+ }
1503
+ return acc;
1504
+ };
1505
+ Uniq2.toArray = (s) => [...s];
1506
+ })(Uniq || (Uniq = {}));
1507
+ // Annotate the CommonJS export names for ESM import in node:
1508
+ 0 && (module.exports = {
1509
+ Arr,
1510
+ Brand,
1511
+ Deferred,
1512
+ Dict,
1513
+ Lens,
1514
+ Logged,
1515
+ Num,
1516
+ Option,
1517
+ Optional,
1518
+ Predicate,
1519
+ Reader,
1520
+ Rec,
1521
+ Refinement,
1522
+ RemoteData,
1523
+ Resource,
1524
+ Result,
1525
+ State,
1526
+ Str,
1527
+ Task,
1528
+ TaskOption,
1529
+ TaskResult,
1530
+ TaskValidation,
1531
+ These,
1532
+ Tuple,
1533
+ Uniq,
1534
+ Validation,
1535
+ and,
1536
+ compose,
1537
+ constFalse,
1538
+ constNull,
1539
+ constTrue,
1540
+ constUndefined,
1541
+ constVoid,
1542
+ constant,
1543
+ converge,
1544
+ curry,
1545
+ curry3,
1546
+ curry4,
1547
+ flip,
1548
+ flow,
1549
+ identity,
1550
+ isNonEmptyList,
1551
+ juxt,
1552
+ memoize,
1553
+ memoizeWeak,
1554
+ not,
1555
+ on,
1556
+ once,
1557
+ or,
1558
+ pipe,
1559
+ tap,
1560
+ uncurry,
1561
+ uncurry3,
1562
+ uncurry4
1563
+ });