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