@nlozgachev/pipelined 0.33.0 → 0.34.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 CHANGED
@@ -87,44 +87,54 @@ module.exports = __toCommonJS(src_exports);
87
87
  function compose(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9) {
88
88
  const len = arguments.length;
89
89
  switch (len) {
90
- case 1:
90
+ case 1: {
91
91
  return f0;
92
- case 2:
92
+ }
93
+ case 2: {
93
94
  return function() {
94
95
  return f0(f1.apply(this, arguments));
95
96
  };
96
- case 3:
97
+ }
98
+ case 3: {
97
99
  return function() {
98
100
  return f0(f1(f2.apply(this, arguments)));
99
101
  };
100
- case 4:
102
+ }
103
+ case 4: {
101
104
  return function() {
102
105
  return f0(f1(f2(f3.apply(this, arguments))));
103
106
  };
104
- case 5:
107
+ }
108
+ case 5: {
105
109
  return function() {
106
110
  return f0(f1(f2(f3(f4.apply(this, arguments)))));
107
111
  };
108
- case 6:
112
+ }
113
+ case 6: {
109
114
  return function() {
110
115
  return f0(f1(f2(f3(f4(f5.apply(this, arguments))))));
111
116
  };
112
- case 7:
117
+ }
118
+ case 7: {
113
119
  return function() {
114
120
  return f0(f1(f2(f3(f4(f5(f6.apply(this, arguments)))))));
115
121
  };
116
- case 8:
122
+ }
123
+ case 8: {
117
124
  return function() {
118
125
  return f0(f1(f2(f3(f4(f5(f6(f7.apply(this, arguments))))))));
119
126
  };
120
- case 9:
127
+ }
128
+ case 9: {
121
129
  return function() {
122
130
  return f0(f1(f2(f3(f4(f5(f6(f7(f8.apply(this, arguments)))))))));
123
131
  };
124
- case 10:
132
+ }
133
+ case 10: {
125
134
  return function() {
126
135
  return f0(f1(f2(f3(f4(f5(f6(f7(f8(f9.apply(this, arguments))))))))));
127
136
  };
137
+ }
128
138
  }
129
139
  }
130
140
 
@@ -145,48 +155,59 @@ var flip = (f) => (b) => (a) => f(a)(b);
145
155
  function flow(ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
146
156
  const len = arguments.length;
147
157
  switch (len) {
148
- case 0:
158
+ case 0: {
149
159
  return function(...args) {
150
160
  return args[0];
151
161
  };
152
- case 1:
162
+ }
163
+ case 1: {
153
164
  return ab;
154
- case 2:
165
+ }
166
+ case 2: {
155
167
  return function() {
156
168
  return bc(ab.apply(this, arguments));
157
169
  };
158
- case 3:
170
+ }
171
+ case 3: {
159
172
  return function() {
160
173
  return cd(bc(ab.apply(this, arguments)));
161
174
  };
162
- case 4:
175
+ }
176
+ case 4: {
163
177
  return function() {
164
178
  return de(cd(bc(ab.apply(this, arguments))));
165
179
  };
166
- case 5:
180
+ }
181
+ case 5: {
167
182
  return function() {
168
183
  return ef(de(cd(bc(ab.apply(this, arguments)))));
169
184
  };
170
- case 6:
185
+ }
186
+ case 6: {
171
187
  return function() {
172
188
  return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
173
189
  };
174
- case 7:
190
+ }
191
+ case 7: {
175
192
  return function() {
176
193
  return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
177
194
  };
178
- case 8:
195
+ }
196
+ case 8: {
179
197
  return function() {
180
198
  return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
181
199
  };
182
- case 9:
200
+ }
201
+ case 9: {
183
202
  return function() {
184
203
  return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
185
204
  };
186
- case 10:
205
+ }
206
+ case 10: {
187
207
  return function() {
188
208
  return jk(ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))))));
189
209
  };
210
+ }
190
211
  }
191
212
  }
192
213
 
@@ -252,28 +273,39 @@ var on = (f, g) => (a, b) => f(g(a), g(b));
252
273
  // src/Composition/pipe.ts
253
274
  function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk) {
254
275
  switch (arguments.length) {
255
- case 1:
276
+ case 1: {
256
277
  return a;
257
- case 2:
278
+ }
279
+ case 2: {
258
280
  return ab(a);
259
- case 3:
281
+ }
282
+ case 3: {
260
283
  return bc(ab(a));
261
- case 4:
284
+ }
285
+ case 4: {
262
286
  return cd(bc(ab(a)));
263
- case 5:
287
+ }
288
+ case 5: {
264
289
  return de(cd(bc(ab(a))));
265
- case 6:
290
+ }
291
+ case 6: {
266
292
  return ef(de(cd(bc(ab(a)))));
267
- case 7:
293
+ }
294
+ case 7: {
268
295
  return fg(ef(de(cd(bc(ab(a))))));
269
- case 8:
296
+ }
297
+ case 8: {
270
298
  return gh(fg(ef(de(cd(bc(ab(a)))))));
271
- case 9:
299
+ }
300
+ case 9: {
272
301
  return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
273
- case 10:
302
+ }
303
+ case 10: {
274
304
  return ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))));
275
- case 11:
305
+ }
306
+ case 11: {
276
307
  return jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))));
308
+ }
277
309
  }
278
310
  }
279
311
 
@@ -297,44 +329,48 @@ var uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
297
329
  var Result;
298
330
  ((Result2) => {
299
331
  Result2.ok = (value) => ({ kind: "Ok", value });
300
- Result2.error = (e) => ({ kind: "Error", error: e });
332
+ Result2.err = (e) => ({ kind: "Err", error: e });
301
333
  Result2.isOk = (data) => data.kind === "Ok";
302
- Result2.isError = (data) => data.kind === "Error";
334
+ Result2.isErr = (data) => data.kind === "Err";
303
335
  Result2.tryCatch = (f, onError) => {
304
336
  try {
305
337
  return (0, Result2.ok)(f());
306
- } catch (e) {
307
- return (0, Result2.error)(onError(e));
338
+ } catch (error) {
339
+ return (0, Result2.err)(onError(error));
308
340
  }
309
341
  };
310
342
  Result2.map = (f) => (data) => (0, Result2.isOk)(data) ? (0, Result2.ok)(f(data.value)) : data;
311
- Result2.mapError = (f) => (data) => (0, Result2.isError)(data) ? (0, Result2.error)(f(data.error)) : data;
343
+ Result2.mapError = (f) => (data) => (0, Result2.isErr)(data) ? (0, Result2.err)(f(data.error)) : data;
312
344
  Result2.chain = (f) => (data) => (0, Result2.isOk)(data) ? f(data.value) : data;
313
345
  Result2.fold = (onErr, onOk) => (data) => (0, Result2.isOk)(data) ? onOk(data.value) : onErr(data.error);
314
346
  Result2.match = (cases) => (data) => (0, Result2.isOk)(data) ? cases.ok(data.value) : cases.err(data.error);
315
347
  Result2.getOrElse = (defaultValue) => (data) => (0, Result2.isOk)(data) ? data.value : defaultValue();
316
348
  Result2.tap = (f) => (data) => {
317
- if ((0, Result2.isOk)(data)) f(data.value);
349
+ if ((0, Result2.isOk)(data)) {
350
+ f(data.value);
351
+ }
318
352
  return data;
319
353
  };
320
354
  Result2.tapError = (f) => (data) => {
321
- if ((0, Result2.isError)(data)) f(data.error);
355
+ if ((0, Result2.isErr)(data)) {
356
+ f(data.error);
357
+ }
322
358
  return data;
323
359
  };
324
- Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.error)(onFalse(a));
325
- Result2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Result2.error)(onNull()) : (0, Result2.ok)(value);
326
- Result2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Result2.error)(onNone()) : (0, Result2.ok)(maybe.value);
360
+ Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.err)(onFalse(a));
361
+ Result2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Result2.err)(onNull()) : (0, Result2.ok)(value);
362
+ Result2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Result2.err)(onNone()) : (0, Result2.ok)(maybe.value);
327
363
  Result2.fromThrowable = (f, onError) => (...args) => {
328
364
  try {
329
365
  return (0, Result2.ok)(f(...args));
330
- } catch (e) {
331
- return (0, Result2.error)(onError(e));
366
+ } catch (error) {
367
+ return (0, Result2.err)(onError(error));
332
368
  }
333
369
  };
334
370
  Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
335
- Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isError)(data) && !isBlocked(data.error) ? fallback() : data;
371
+ Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isErr)(data) && !isBlocked(data.error) ? fallback() : data;
336
372
  Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
337
- Result2.ap = (arg) => (data) => (0, Result2.isOk)(data) && (0, Result2.isOk)(arg) ? (0, Result2.ok)(data.value(arg.value)) : (0, Result2.isError)(data) ? data : arg;
373
+ 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;
338
374
  })(Result || (Result = {}));
339
375
 
340
376
  // src/Core/Maybe.ts
@@ -349,7 +385,7 @@ var Maybe;
349
385
  Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
350
386
  Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
351
387
  Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
352
- Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.error(onNone());
388
+ Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
353
389
  Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
354
390
  Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
355
391
  Maybe2.chain = (f) => (data) => (0, Maybe2.isSome)(data) ? f(data.value) : data;
@@ -357,7 +393,9 @@ var Maybe;
357
393
  Maybe2.match = (cases) => (data) => (0, Maybe2.isSome)(data) ? cases.some(data.value) : cases.none();
358
394
  Maybe2.getOrElse = (defaultValue) => (data) => (0, Maybe2.isSome)(data) ? data.value : defaultValue();
359
395
  Maybe2.tap = (f) => (data) => {
360
- if ((0, Maybe2.isSome)(data)) f(data.value);
396
+ if ((0, Maybe2.isSome)(data)) {
397
+ f(data.value);
398
+ }
361
399
  return data;
362
400
  };
363
401
  Maybe2.filter = (predicate) => (data) => (0, Maybe2.isSome)(data) ? predicate(data.value) ? data : (0, Maybe2.none)() : data;
@@ -368,30 +406,12 @@ var Maybe;
368
406
  // src/Core/Combinable.ts
369
407
  var Combinable;
370
408
  ((Combinable2) => {
371
- Combinable2.string = {
372
- empty: "",
373
- combine: (b) => (a) => a + b
374
- };
375
- Combinable2.sum = {
376
- empty: 0,
377
- combine: (b) => (a) => a + b
378
- };
379
- Combinable2.product = {
380
- empty: 1,
381
- combine: (b) => (a) => a * b
382
- };
383
- Combinable2.all = {
384
- empty: true,
385
- combine: (b) => (a) => a && b
386
- };
387
- Combinable2.any = {
388
- empty: false,
389
- combine: (b) => (a) => a || b
390
- };
391
- Combinable2.array = () => ({
392
- empty: [],
393
- combine: (b) => (a) => [...a, ...b]
394
- });
409
+ Combinable2.string = { empty: "", combine: (b) => (a) => a + b };
410
+ Combinable2.sum = { empty: 0, combine: (b) => (a) => a + b };
411
+ Combinable2.product = { empty: 1, combine: (b) => (a) => a * b };
412
+ Combinable2.all = { empty: true, combine: (b) => (a) => a && b };
413
+ Combinable2.any = { empty: false, combine: (b) => (a) => a || b };
414
+ Combinable2.array = () => ({ empty: [], combine: (b) => (a) => [...a, ...b] });
395
415
  Combinable2.maybe = (inner) => ({
396
416
  empty: Maybe.none(),
397
417
  combine: (b) => (a) => Maybe.isNone(a) ? b : Maybe.isNone(b) ? a : Maybe.some(inner.combine(b.value)(a.value))
@@ -451,17 +471,11 @@ var Lazy;
451
471
  var Lens;
452
472
  ((Lens2) => {
453
473
  Lens2.make = (get2, set2) => ({ get: get2, set: set2 });
454
- Lens2.prop = () => (key) => (0, Lens2.make)(
455
- (s) => s[key],
456
- (a) => (s) => ({ ...s, [key]: a })
457
- );
474
+ Lens2.prop = () => (key) => (0, Lens2.make)((s) => s[key], (a) => (s) => ({ ...s, [key]: a }));
458
475
  Lens2.get = (lens) => (s) => lens.get(s);
459
476
  Lens2.set = (lens) => (a) => (s) => lens.set(a)(s);
460
477
  Lens2.modify = (lens) => (f) => (s) => lens.set(f(lens.get(s)))(s);
461
- Lens2.andThen = (inner) => (outer) => (0, Lens2.make)(
462
- (s) => inner.get(outer.get(s)),
463
- (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
464
- );
478
+ Lens2.andThen = (inner) => (outer) => (0, Lens2.make)((s) => inner.get(outer.get(s)), (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s));
465
479
  Lens2.andThenOptional = (inner) => (outer) => ({
466
480
  get: (s) => inner.get(outer.get(s)),
467
481
  set: (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
@@ -496,6 +510,31 @@ var Logged;
496
510
  Logged2.run = (data) => [data.value, data.log];
497
511
  })(Logged || (Logged = {}));
498
512
 
513
+ // src/Types/Brand.ts
514
+ var Brand;
515
+ ((Brand2) => {
516
+ Brand2.wrap = () => (value) => value;
517
+ Brand2.unwrap = (branded) => branded;
518
+ })(Brand || (Brand = {}));
519
+
520
+ // src/Types/Duration.ts
521
+ var Duration;
522
+ ((Duration2) => {
523
+ const wrap = Brand.wrap();
524
+ Duration2.milliseconds = (ms) => wrap(ms);
525
+ Duration2.seconds = (s) => wrap(s * 1e3);
526
+ Duration2.minutes = (m) => wrap(m * 60 * 1e3);
527
+ Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
528
+ Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
529
+ Duration2.toMilliseconds = (d) => Brand.unwrap(d);
530
+ Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
531
+ Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
532
+ Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
533
+ Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
534
+ Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
535
+ Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
536
+ })(Duration || (Duration = {}));
537
+
499
538
  // src/internal/Op.util.ts
500
539
  var _abortedNil = { kind: "OpNil", reason: "aborted" };
501
540
  var _droppedNil = { kind: "OpNil", reason: "dropped" };
@@ -504,11 +543,15 @@ var _evictedNil = { kind: "OpNil", reason: "evicted" };
504
543
  var _idle = { kind: "Idle" };
505
544
  var _pending = { kind: "Pending" };
506
545
  var ok = (value) => ({ kind: "OpOk", value });
507
- var err = (error) => ({ kind: "OpError", error });
508
- var cancellableWait = (ms, signal) => {
509
- if (ms <= 0) return Promise.resolve();
546
+ var err = (error) => ({ kind: "OpErr", error });
547
+ var getMs = (duration) => Duration.toMilliseconds(duration);
548
+ var cancellableWait = (duration, signal) => {
549
+ const rawMs = getMs(duration);
550
+ if (rawMs <= 0) {
551
+ return Promise.resolve();
552
+ }
510
553
  return new Promise((resolve) => {
511
- const id = setTimeout(resolve, ms);
554
+ const id = setTimeout(resolve, rawMs);
512
555
  signal.addEventListener("abort", () => {
513
556
  clearTimeout(id);
514
557
  resolve();
@@ -517,23 +560,41 @@ var cancellableWait = (ms, signal) => {
517
560
  };
518
561
  var runWithRetry = (op, input, signal, options, onRetrying) => {
519
562
  const { attempts, backoff, when: shouldRetry } = options;
520
- const getDelay = (n) => backoff === void 0 ? 0 : typeof backoff === "function" ? backoff(n) : backoff;
563
+ const getDelay = (n) => {
564
+ if (backoff === void 0) {
565
+ return void 0;
566
+ }
567
+ return typeof backoff === "function" ? backoff(n) : backoff;
568
+ };
521
569
  const attempt = async (left) => {
522
570
  const result = await Deferred.toPromise(op._factory(input, signal));
523
- if (result === null || signal.aborted) return null;
524
- if (result.kind === "Ok") return result;
525
- if (left <= 1) return result;
526
- if (shouldRetry !== void 0 && !shouldRetry(result.error)) return result;
571
+ if (result === null || signal.aborted) {
572
+ return null;
573
+ }
574
+ if (result.kind === "Ok") {
575
+ return result;
576
+ }
577
+ if (left <= 1) {
578
+ return result;
579
+ }
580
+ if (shouldRetry !== void 0 && !shouldRetry(result.error)) {
581
+ return result;
582
+ }
527
583
  const attemptNumber = attempts - left + 1;
528
- const ms = getDelay(attemptNumber);
584
+ const delayDuration = getDelay(attemptNumber);
585
+ const ms = delayDuration ? getMs(delayDuration) : 0;
529
586
  onRetrying({
530
587
  kind: "Retrying",
531
588
  attempt: attemptNumber,
532
589
  lastError: result.error,
533
590
  ...ms > 0 ? { nextRetryIn: ms } : {}
534
591
  });
535
- await cancellableWait(ms, signal);
536
- if (signal.aborted) return null;
592
+ if (delayDuration) {
593
+ await cancellableWait(delayDuration, signal);
594
+ }
595
+ if (signal.aborted) {
596
+ return null;
597
+ }
537
598
  return attempt(left - 1);
538
599
  };
539
600
  return attempt(attempts);
@@ -542,7 +603,9 @@ var execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying)
542
603
  const { signal } = controller;
543
604
  const toOutcome = (r) => r === null ? _abortedNil : r.kind === "Ok" ? ok(r.value) : err(r.error);
544
605
  const runPromise = retryOptions !== void 0 && onRetrying !== void 0 ? runWithRetry(op, input, signal, retryOptions, onRetrying).then(toOutcome) : Deferred.toPromise(op._factory(input, signal)).then(toOutcome);
545
- if (timeoutOptions === void 0) return Deferred.fromPromise(runPromise);
606
+ if (timeoutOptions === void 0) {
607
+ return Deferred.fromPromise(runPromise);
608
+ }
546
609
  let timerId;
547
610
  return Deferred.fromPromise(Promise.race([
548
611
  runPromise.then((outcome) => {
@@ -553,7 +616,7 @@ var execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying)
553
616
  timerId = setTimeout(() => {
554
617
  controller.abort();
555
618
  resolve(err(timeoutOptions.onTimeout()));
556
- }, timeoutOptions.ms);
619
+ }, getMs(timeoutOptions.duration));
557
620
  })
558
621
  ]));
559
622
  };
@@ -579,14 +642,20 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
579
642
  const controller = currentController;
580
643
  prev?.(_replacedNil);
581
644
  const startExecution = () => {
582
- if (currentController !== controller) return;
645
+ if (currentController !== controller) {
646
+ return;
647
+ }
583
648
  lastStartTime = Date.now();
584
649
  emit(_pending);
585
650
  const onRetrying = retryOptions ? (r) => {
586
- if (currentController === controller) emit(r);
651
+ if (currentController === controller) {
652
+ emit(r);
653
+ }
587
654
  } : void 0;
588
655
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
589
- if (currentController !== controller) return;
656
+ if (currentController !== controller) {
657
+ return;
658
+ }
590
659
  const r = currentResolve;
591
660
  currentResolve = void 0;
592
661
  currentController = void 0;
@@ -594,12 +663,14 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
594
663
  r?.(outcome);
595
664
  });
596
665
  };
597
- const gap = minInterval !== void 0 ? Math.max(0, minInterval - (Date.now() - lastStartTime)) : 0;
666
+ const gap = minInterval !== void 0 ? Math.max(0, getMs(minInterval) - (Date.now() - lastStartTime)) : 0;
598
667
  if (gap > 0) {
599
668
  waitController = new AbortController();
600
669
  const wc = waitController;
601
- cancellableWait(gap, wc.signal).then(() => {
602
- if (waitController === wc) waitController = void 0;
670
+ cancellableWait(Duration.milliseconds(gap), wc.signal).then(() => {
671
+ if (waitController === wc) {
672
+ waitController = void 0;
673
+ }
603
674
  startExecution();
604
675
  });
605
676
  } else {
@@ -614,7 +685,9 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
614
685
  currentController = void 0;
615
686
  const r = currentResolve;
616
687
  currentResolve = void 0;
617
- if (currentState.kind !== "Idle") emit(_abortedNil);
688
+ if (currentState.kind !== "Idle") {
689
+ emit(_abortedNil);
690
+ }
618
691
  r?.(_abortedNil);
619
692
  };
620
693
  return {
@@ -625,13 +698,15 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
625
698
  abort,
626
699
  subscribe: (cb) => {
627
700
  subscribers.add(cb);
628
- if (currentState.kind !== "Idle") cb(currentState);
701
+ if (currentState.kind !== "Idle") {
702
+ cb(currentState);
703
+ }
629
704
  return () => subscribers.delete(cb);
630
705
  },
631
706
  reset: () => emit(_idle),
632
707
  poll: (input, { interval }) => {
633
708
  void run(input);
634
- const id = setInterval(() => void run(input), interval);
709
+ const id = setInterval(() => void run(input), getMs(interval));
635
710
  return () => clearInterval(id);
636
711
  }
637
712
  };
@@ -657,19 +732,26 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
657
732
  const controller = currentController;
658
733
  emit(_pending);
659
734
  const onRetrying = retryOptions ? (r) => {
660
- if (currentController === controller) emit(r);
735
+ if (currentController === controller) {
736
+ emit(r);
737
+ }
661
738
  } : void 0;
662
739
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
663
- if (currentController !== controller) return;
740
+ if (currentController !== controller) {
741
+ return;
742
+ }
664
743
  const r = currentResolve;
665
744
  currentResolve = void 0;
666
745
  currentController = void 0;
667
746
  emit(outcome);
668
747
  r?.(outcome);
669
- if (cooldown !== void 0 && cooldown > 0) {
670
- cooldownTimer = setTimeout(() => {
671
- cooldownTimer = void 0;
672
- }, cooldown);
748
+ if (cooldown !== void 0) {
749
+ const rawCooldown = getMs(cooldown);
750
+ if (rawCooldown > 0) {
751
+ cooldownTimer = setTimeout(() => {
752
+ cooldownTimer = void 0;
753
+ }, rawCooldown);
754
+ }
673
755
  }
674
756
  });
675
757
  })
@@ -684,7 +766,9 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
684
766
  currentController = void 0;
685
767
  const r = currentResolve;
686
768
  currentResolve = void 0;
687
- if (currentState.kind !== "Idle") emit(_abortedNil);
769
+ if (currentState.kind !== "Idle") {
770
+ emit(_abortedNil);
771
+ }
688
772
  r?.(_abortedNil);
689
773
  };
690
774
  return {
@@ -695,13 +779,15 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
695
779
  abort,
696
780
  subscribe: (cb) => {
697
781
  subscribers.add(cb);
698
- if (currentState.kind !== "Idle") cb(currentState);
782
+ if (currentState.kind !== "Idle") {
783
+ cb(currentState);
784
+ }
699
785
  return () => subscribers.delete(cb);
700
786
  },
701
787
  reset: () => emit(_idle),
702
788
  poll: (input, { interval }) => {
703
789
  void run(input);
704
- const id = setInterval(() => void run(input), interval);
790
+ const id = setInterval(() => void run(input), getMs(interval));
705
791
  return () => clearInterval(id);
706
792
  }
707
793
  };
@@ -726,12 +812,16 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
726
812
  inflightResolvers.push(resolve);
727
813
  emit(_pending);
728
814
  const onRetrying = retryOptions ? (r) => {
729
- if (generation === myGeneration && inflightControllers.has(controller)) emit(r);
815
+ if (generation === myGeneration && inflightControllers.has(controller)) {
816
+ emit(r);
817
+ }
730
818
  } : void 0;
731
819
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
732
820
  inflightControllers.delete(controller);
733
821
  const idx = inflightResolvers.indexOf(resolve);
734
- if (idx !== -1) inflightResolvers.splice(idx, 1);
822
+ if (idx !== -1) {
823
+ inflightResolvers.splice(idx, 1);
824
+ }
735
825
  if (generation !== myGeneration) {
736
826
  resolve(_abortedNil);
737
827
  return;
@@ -788,7 +878,9 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
788
878
  const toResolve = inflightResolvers.splice(0);
789
879
  const queuedResolvers = queue.splice(0).map((item) => item.resolve);
790
880
  inFlight = 0;
791
- if (currentState.kind !== "Idle") emit(_abortedNil);
881
+ if (currentState.kind !== "Idle") {
882
+ emit(_abortedNil);
883
+ }
792
884
  toResolve.forEach((r) => r(_abortedNil));
793
885
  queuedResolvers.forEach((r) => r(_abortedNil));
794
886
  };
@@ -800,13 +892,15 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
800
892
  abort,
801
893
  subscribe: (cb) => {
802
894
  subscribers.add(cb);
803
- if (currentState.kind !== "Idle") cb(currentState);
895
+ if (currentState.kind !== "Idle") {
896
+ cb(currentState);
897
+ }
804
898
  return () => subscribers.delete(cb);
805
899
  },
806
900
  reset: () => emit(_idle),
807
901
  poll: (input, { interval }) => {
808
902
  void run(input);
809
- const id = setInterval(() => void run(input), interval);
903
+ const id = setInterval(() => void run(input), getMs(interval));
810
904
  return () => clearInterval(id);
811
905
  }
812
906
  };
@@ -828,10 +922,14 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
828
922
  const controller = currentController;
829
923
  emit(_pending);
830
924
  const onRetrying = retryOptions ? (r) => {
831
- if (currentController === controller) emit(r);
925
+ if (currentController === controller) {
926
+ emit(r);
927
+ }
832
928
  } : void 0;
833
929
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
834
- if (currentController !== controller) return;
930
+ if (currentController !== controller) {
931
+ return;
932
+ }
835
933
  const r = currentResolve;
836
934
  currentResolve = void 0;
837
935
  currentController = void 0;
@@ -864,7 +962,9 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
864
962
  const cr = currentResolve;
865
963
  currentResolve = void 0;
866
964
  const bufferedResolvers = buffer.splice(0).map((item) => item.resolve);
867
- if (currentState.kind !== "Idle") emit(_abortedNil);
965
+ if (currentState.kind !== "Idle") {
966
+ emit(_abortedNil);
967
+ }
868
968
  cr?.(_abortedNil);
869
969
  bufferedResolvers.forEach((r) => r(_abortedNil));
870
970
  };
@@ -876,18 +976,20 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
876
976
  abort,
877
977
  subscribe: (cb) => {
878
978
  subscribers.add(cb);
879
- if (currentState.kind !== "Idle") cb(currentState);
979
+ if (currentState.kind !== "Idle") {
980
+ cb(currentState);
981
+ }
880
982
  return () => subscribers.delete(cb);
881
983
  },
882
984
  reset: () => emit(_idle),
883
985
  poll: (input, { interval }) => {
884
986
  void run(input);
885
- const id = setInterval(() => void run(input), interval);
987
+ const id = setInterval(() => void run(input), getMs(interval));
886
988
  return () => clearInterval(id);
887
989
  }
888
990
  };
889
991
  };
890
- var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) => {
992
+ var makeDebounced = (op, duration, leading, maxWait, retryOptions, timeoutOptions) => {
891
993
  let currentState = _idle;
892
994
  let currentController;
893
995
  let currentResolve;
@@ -908,10 +1010,14 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
908
1010
  leadingResolve = resolve;
909
1011
  emit(_pending);
910
1012
  const onRetrying = retryOptions ? (r) => {
911
- if (leadingController === controller) emit(r);
1013
+ if (leadingController === controller) {
1014
+ emit(r);
1015
+ }
912
1016
  } : void 0;
913
1017
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
914
- if (leadingController !== controller) return;
1018
+ if (leadingController !== controller) {
1019
+ return;
1020
+ }
915
1021
  const r = leadingResolve;
916
1022
  leadingResolve = void 0;
917
1023
  leadingController = void 0;
@@ -924,7 +1030,9 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
924
1030
  firstCallAt = 0;
925
1031
  const capturedResolve = pendingResolve;
926
1032
  pendingResolve = void 0;
927
- if (capturedResolve === void 0) return;
1033
+ if (capturedResolve === void 0) {
1034
+ return;
1035
+ }
928
1036
  currentResolve = capturedResolve;
929
1037
  const toRun = pendingInput;
930
1038
  pendingInput = void 0;
@@ -932,10 +1040,14 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
932
1040
  const controller = currentController;
933
1041
  emit(_pending);
934
1042
  const onRetrying = retryOptions ? (r) => {
935
- if (currentController === controller) emit(r);
1043
+ if (currentController === controller) {
1044
+ emit(r);
1045
+ }
936
1046
  } : void 0;
937
1047
  execute(op, toRun, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
938
- if (currentController !== controller) return;
1048
+ if (currentController !== controller) {
1049
+ return;
1050
+ }
939
1051
  const r = currentResolve;
940
1052
  currentResolve = void 0;
941
1053
  currentController = void 0;
@@ -944,11 +1056,13 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
944
1056
  });
945
1057
  };
946
1058
  const scheduleTrailing = () => {
947
- if (timerId !== void 0) clearTimeout(timerId);
948
- let delay = ms;
1059
+ if (timerId !== void 0) {
1060
+ clearTimeout(timerId);
1061
+ }
1062
+ let delay = getMs(duration);
949
1063
  if (maxWait !== void 0 && firstCallAt > 0) {
950
- const maxDelay = firstCallAt + maxWait - Date.now();
951
- delay = Math.min(ms, Math.max(0, maxDelay));
1064
+ const maxDelay = firstCallAt + getMs(maxWait) - Date.now();
1065
+ delay = Math.min(getMs(duration), Math.max(0, maxDelay));
952
1066
  }
953
1067
  timerId = setTimeout(fireTrailing, delay);
954
1068
  };
@@ -991,7 +1105,9 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
991
1105
  leadingResolve = void 0;
992
1106
  leadingController?.abort();
993
1107
  leadingController = void 0;
994
- if (currentState.kind !== "Idle") emit(_abortedNil);
1108
+ if (currentState.kind !== "Idle") {
1109
+ emit(_abortedNil);
1110
+ }
995
1111
  pr?.(_abortedNil);
996
1112
  cr?.(_abortedNil);
997
1113
  lr?.(_abortedNil);
@@ -1004,18 +1120,20 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
1004
1120
  abort,
1005
1121
  subscribe: (cb) => {
1006
1122
  subscribers.add(cb);
1007
- if (currentState.kind !== "Idle") cb(currentState);
1123
+ if (currentState.kind !== "Idle") {
1124
+ cb(currentState);
1125
+ }
1008
1126
  return () => subscribers.delete(cb);
1009
1127
  },
1010
1128
  reset: () => emit(_idle),
1011
1129
  poll: (input, { interval }) => {
1012
1130
  void run(input);
1013
- const id = setInterval(() => void run(input), interval);
1131
+ const id = setInterval(() => void run(input), getMs(interval));
1014
1132
  return () => clearInterval(id);
1015
1133
  }
1016
1134
  };
1017
1135
  };
1018
- var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
1136
+ var makeThrottled = (op, duration, trailing, retryOptions, timeoutOptions) => {
1019
1137
  let currentState = _idle;
1020
1138
  let currentController;
1021
1139
  let currentResolve;
@@ -1033,10 +1151,14 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
1033
1151
  const controller = currentController;
1034
1152
  emit(_pending);
1035
1153
  const onRetrying = retryOptions ? (r) => {
1036
- if (currentController === controller) emit(r);
1154
+ if (currentController === controller) {
1155
+ emit(r);
1156
+ }
1037
1157
  } : void 0;
1038
1158
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
1039
- if (currentController !== controller) return;
1159
+ if (currentController !== controller) {
1160
+ return;
1161
+ }
1040
1162
  const r = currentResolve;
1041
1163
  currentResolve = void 0;
1042
1164
  currentController = void 0;
@@ -1055,7 +1177,7 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
1055
1177
  fireOp(input, resolve);
1056
1178
  startCooldown();
1057
1179
  }
1058
- }, ms);
1180
+ }, getMs(duration));
1059
1181
  };
1060
1182
  const run = (input) => {
1061
1183
  if (cooldownTimer !== void 0) {
@@ -1090,7 +1212,9 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
1090
1212
  const pr = pendingResolve;
1091
1213
  pendingResolve = void 0;
1092
1214
  pendingInput = void 0;
1093
- if (currentState.kind !== "Idle") emit(_abortedNil);
1215
+ if (currentState.kind !== "Idle") {
1216
+ emit(_abortedNil);
1217
+ }
1094
1218
  cr?.(_abortedNil);
1095
1219
  pr?.(_abortedNil);
1096
1220
  };
@@ -1102,13 +1226,15 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
1102
1226
  abort,
1103
1227
  subscribe: (cb) => {
1104
1228
  subscribers.add(cb);
1105
- if (currentState.kind !== "Idle") cb(currentState);
1229
+ if (currentState.kind !== "Idle") {
1230
+ cb(currentState);
1231
+ }
1106
1232
  return () => subscribers.delete(cb);
1107
1233
  },
1108
1234
  reset: () => emit(_idle),
1109
1235
  poll: (input, { interval }) => {
1110
1236
  void run(input);
1111
- const id = setInterval(() => void run(input), interval);
1237
+ const id = setInterval(() => void run(input), getMs(interval));
1112
1238
  return () => clearInterval(id);
1113
1239
  }
1114
1240
  };
@@ -1132,12 +1258,16 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
1132
1258
  inflightResolvers.push(resolve);
1133
1259
  emit(_pending);
1134
1260
  const onRetrying = retryOptions ? (r) => {
1135
- if (generation === myGeneration && controllers.has(controller)) emit(r);
1261
+ if (generation === myGeneration && controllers.has(controller)) {
1262
+ emit(r);
1263
+ }
1136
1264
  } : void 0;
1137
1265
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
1138
1266
  controllers.delete(controller);
1139
1267
  const idx = inflightResolvers.indexOf(resolve);
1140
- if (idx !== -1) inflightResolvers.splice(idx, 1);
1268
+ if (idx !== -1) {
1269
+ inflightResolvers.splice(idx, 1);
1270
+ }
1141
1271
  if (generation !== myGeneration) {
1142
1272
  resolve(_abortedNil);
1143
1273
  return;
@@ -1177,7 +1307,9 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
1177
1307
  const toResolve = inflightResolvers.splice(0);
1178
1308
  const queuedResolvers = overflowQueue.splice(0).map((item) => item.resolve);
1179
1309
  inflight = 0;
1180
- if (currentState.kind !== "Idle") emit(_abortedNil);
1310
+ if (currentState.kind !== "Idle") {
1311
+ emit(_abortedNil);
1312
+ }
1181
1313
  toResolve.forEach((r) => r(_abortedNil));
1182
1314
  queuedResolvers.forEach((r) => r(_abortedNil));
1183
1315
  };
@@ -1189,13 +1321,15 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
1189
1321
  abort,
1190
1322
  subscribe: (cb) => {
1191
1323
  subscribers.add(cb);
1192
- if (currentState.kind !== "Idle") cb(currentState);
1324
+ if (currentState.kind !== "Idle") {
1325
+ cb(currentState);
1326
+ }
1193
1327
  return () => subscribers.delete(cb);
1194
1328
  },
1195
1329
  reset: () => emit(_idle),
1196
1330
  poll: (input, { interval }) => {
1197
1331
  void run(input);
1198
- const id = setInterval(() => void run(input), interval);
1332
+ const id = setInterval(() => void run(input), getMs(interval));
1199
1333
  return () => clearInterval(id);
1200
1334
  }
1201
1335
  };
@@ -1226,7 +1360,7 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1226
1360
  slots.set(k, { controller, resolve });
1227
1361
  stateMap.set(k, _pending);
1228
1362
  emitSnapshot();
1229
- execute(op, input, controller, void 0, timeoutOptions, void 0).then((outcome) => {
1363
+ execute(op, input, controller, void 0, timeoutOptions).then((outcome) => {
1230
1364
  const slot = slots.get(k);
1231
1365
  if (!slot || slot.controller !== controller) {
1232
1366
  resolve(_abortedNil);
@@ -1259,7 +1393,9 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1259
1393
  stateMap.set(k, _abortedNil);
1260
1394
  }
1261
1395
  slots.clear();
1262
- if (toResolve.length > 0) emitSnapshot();
1396
+ if (toResolve.length > 0) {
1397
+ emitSnapshot();
1398
+ }
1263
1399
  toResolve.forEach((r) => r(_abortedNil));
1264
1400
  }
1265
1401
  };
@@ -1271,7 +1407,9 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1271
1407
  abort,
1272
1408
  subscribe: (cb) => {
1273
1409
  subscribers.add(cb);
1274
- if (stateMap.size > 0) cb(new Map(stateMap));
1410
+ if (stateMap.size > 0) {
1411
+ cb(new Map(stateMap));
1412
+ }
1275
1413
  return () => subscribers.delete(cb);
1276
1414
  },
1277
1415
  reset: () => {
@@ -1280,7 +1418,7 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1280
1418
  },
1281
1419
  poll: (input, { interval }) => {
1282
1420
  void run(input);
1283
- const id = setInterval(() => void run(input), interval);
1421
+ const id = setInterval(() => void run(input), getMs(interval));
1284
1422
  return () => clearInterval(id);
1285
1423
  }
1286
1424
  };
@@ -1305,10 +1443,14 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
1305
1443
  const controller = currentController;
1306
1444
  emit(_pending);
1307
1445
  const onRetrying = retryOptions ? (r) => {
1308
- if (currentController === controller) emit(r);
1446
+ if (currentController === controller) {
1447
+ emit(r);
1448
+ }
1309
1449
  } : void 0;
1310
1450
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
1311
- if (currentController !== controller) return;
1451
+ if (currentController !== controller) {
1452
+ return;
1453
+ }
1312
1454
  const r = currentResolve;
1313
1455
  currentResolve = void 0;
1314
1456
  currentController = void 0;
@@ -1323,7 +1465,9 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
1323
1465
  currentController = void 0;
1324
1466
  const r = currentResolve;
1325
1467
  currentResolve = void 0;
1326
- if (currentState.kind !== "Idle") emit(_abortedNil);
1468
+ if (currentState.kind !== "Idle") {
1469
+ emit(_abortedNil);
1470
+ }
1327
1471
  r?.(_abortedNil);
1328
1472
  };
1329
1473
  return {
@@ -1334,13 +1478,15 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
1334
1478
  abort,
1335
1479
  subscribe: (cb) => {
1336
1480
  subscribers.add(cb);
1337
- if (currentState.kind !== "Idle") cb(currentState);
1481
+ if (currentState.kind !== "Idle") {
1482
+ cb(currentState);
1483
+ }
1338
1484
  return () => subscribers.delete(cb);
1339
1485
  },
1340
1486
  reset: () => emit(_idle),
1341
1487
  poll: (input, { interval }) => {
1342
1488
  void run(input);
1343
- const id = setInterval(() => void run(input), interval);
1489
+ const id = setInterval(() => void run(input), getMs(interval));
1344
1490
  return () => clearInterval(id);
1345
1491
  }
1346
1492
  };
@@ -1352,62 +1498,80 @@ var Op;
1352
1498
  Op2.nil = (reason) => ({ kind: "OpNil", reason });
1353
1499
  Op2.create = (factory, onError) => ({
1354
1500
  _factory: (input, signal) => Deferred.fromPromise(
1355
- factory(signal)(input).then((value) => Result.ok(value)).catch((e) => signal.aborted ? null : Result.error(onError(e)))
1501
+ factory(signal)(input).then((value) => Result.ok(value)).catch(
1502
+ (error) => signal.aborted ? null : Result.err(onError(error))
1503
+ )
1356
1504
  )
1357
1505
  });
1358
- Op2.lift = (f) => (0, Op2.create)(
1359
- (signal) => (input) => f(input, signal),
1360
- (e) => e
1361
- );
1506
+ Op2.lift = (f) => (0, Op2.create)((signal) => (input) => f(input, signal), (e) => e);
1362
1507
  Op2.ok = (value) => ({ kind: "OpOk", value });
1363
- Op2.error = (error2) => ({ kind: "OpError", error: error2 });
1508
+ Op2.err = (error) => ({ kind: "OpErr", error });
1364
1509
  Op2.isIdle = (state) => state.kind === "Idle";
1365
1510
  Op2.isPending = (state) => state.kind === "Pending";
1366
1511
  Op2.isQueued = (state) => state.kind === "Queued";
1367
1512
  Op2.isRetrying = (state) => state.kind === "Retrying";
1368
1513
  Op2.isOk = (state) => state.kind === "OpOk";
1369
- Op2.isError = (state) => state.kind === "OpError";
1514
+ Op2.isErr = (state) => state.kind === "OpErr";
1370
1515
  Op2.isNil = (state) => state.kind === "OpNil";
1371
1516
  Op2.match = (cases) => (outcome) => {
1372
- if (outcome.kind === "OpOk") return cases.ok(outcome.value);
1373
- if (outcome.kind === "OpError") return cases.error(outcome.error);
1517
+ if (outcome.kind === "OpOk") {
1518
+ return cases.ok(outcome.value);
1519
+ }
1520
+ if (outcome.kind === "OpErr") {
1521
+ return cases.err(outcome.error);
1522
+ }
1374
1523
  return cases.nil();
1375
1524
  };
1376
- Op2.fold = (onError, onOk, onNil) => (outcome) => {
1377
- if (outcome.kind === "OpOk") return onOk(outcome.value);
1378
- if (outcome.kind === "OpError") return onError(outcome.error);
1525
+ Op2.fold = (onErr, onOk, onNil) => (outcome) => {
1526
+ if (outcome.kind === "OpOk") {
1527
+ return onOk(outcome.value);
1528
+ }
1529
+ if (outcome.kind === "OpErr") {
1530
+ return onErr(outcome.error);
1531
+ }
1379
1532
  return onNil();
1380
1533
  };
1381
1534
  Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "OpOk" ? outcome.value : defaultValue();
1382
1535
  Op2.map = (f) => (outcome) => outcome.kind === "OpOk" ? (0, Op2.ok)(f(outcome.value)) : outcome;
1383
- Op2.mapError = (f) => (outcome) => outcome.kind === "OpError" ? (0, Op2.error)(f(outcome.error)) : outcome;
1536
+ Op2.mapError = (f) => (outcome) => outcome.kind === "OpErr" ? (0, Op2.err)(f(outcome.error)) : outcome;
1384
1537
  Op2.chain = (f) => (outcome) => outcome.kind === "OpOk" ? f(outcome.value) : outcome;
1385
1538
  Op2.tap = (f) => (outcome) => {
1386
- if (outcome.kind === "OpOk") f(outcome.value);
1539
+ if (outcome.kind === "OpOk") {
1540
+ f(outcome.value);
1541
+ }
1387
1542
  return outcome;
1388
1543
  };
1389
- Op2.recover = (f) => (outcome) => outcome.kind === "OpError" ? f(outcome.error) : outcome;
1544
+ Op2.recover = (f) => (outcome) => outcome.kind === "OpErr" ? f(outcome.error) : outcome;
1390
1545
  Op2.toResult = (onNil) => (outcome) => {
1391
- if (outcome.kind === "OpOk") return Result.ok(outcome.value);
1392
- if (outcome.kind === "OpError") return Result.error(outcome.error);
1393
- return Result.error(onNil());
1546
+ if (outcome.kind === "OpOk") {
1547
+ return Result.ok(outcome.value);
1548
+ }
1549
+ if (outcome.kind === "OpErr") {
1550
+ return Result.err(outcome.error);
1551
+ }
1552
+ return Result.err(onNil());
1394
1553
  };
1395
1554
  Op2.toMaybe = (outcome) => outcome.kind === "OpOk" ? Maybe.some(outcome.value) : Maybe.none();
1396
1555
  Op2.all = (invocations) => Deferred.fromPromise(Promise.all(invocations.map(Deferred.toPromise)));
1397
1556
  Op2.race = (invocations) => Deferred.fromPromise(Promise.race(invocations.map(Deferred.toPromise)));
1398
1557
  Op2.wire = (source, f) => source.subscribe((state) => {
1399
- if ((0, Op2.isOk)(state)) f(state.value);
1558
+ if ((0, Op2.isOk)(state)) {
1559
+ f(state.value);
1560
+ }
1400
1561
  });
1401
1562
  function interpret(op, options) {
1402
1563
  const { strategy, retry: retryOptions, timeout: timeoutOptions } = options;
1403
1564
  switch (strategy) {
1404
- case "once":
1565
+ case "once": {
1405
1566
  return makeOnce(op, retryOptions, timeoutOptions);
1406
- case "restartable":
1567
+ }
1568
+ case "restartable": {
1407
1569
  return makeRestartable(op, options.minInterval, retryOptions, timeoutOptions);
1408
- case "exclusive":
1570
+ }
1571
+ case "exclusive": {
1409
1572
  return makeExclusive(op, options.cooldown, retryOptions, timeoutOptions);
1410
- case "queue":
1573
+ }
1574
+ case "queue": {
1411
1575
  return makeQueue(
1412
1576
  op,
1413
1577
  options.maxSize,
@@ -1417,13 +1581,24 @@ var Op;
1417
1581
  retryOptions,
1418
1582
  timeoutOptions
1419
1583
  );
1420
- case "buffered":
1584
+ }
1585
+ case "buffered": {
1421
1586
  return makeBuffered(op, options.size, retryOptions, timeoutOptions);
1422
- case "debounced":
1423
- return makeDebounced(op, options.ms ?? 0, options.leading ?? false, options.maxWait, retryOptions, timeoutOptions);
1424
- case "throttled":
1425
- return makeThrottled(op, options.ms ?? 0, options.trailing ?? false, retryOptions, timeoutOptions);
1426
- case "concurrent":
1587
+ }
1588
+ case "debounced": {
1589
+ return makeDebounced(
1590
+ op,
1591
+ options.duration,
1592
+ options.leading ?? false,
1593
+ options.maxWait,
1594
+ retryOptions,
1595
+ timeoutOptions
1596
+ );
1597
+ }
1598
+ case "throttled": {
1599
+ return makeThrottled(op, options.duration, options.trailing ?? false, retryOptions, timeoutOptions);
1600
+ }
1601
+ case "concurrent": {
1427
1602
  return makeConcurrent(
1428
1603
  op,
1429
1604
  options.n ?? 1,
@@ -1431,8 +1606,10 @@ var Op;
1431
1606
  retryOptions,
1432
1607
  timeoutOptions
1433
1608
  );
1434
- case "keyed":
1609
+ }
1610
+ case "keyed": {
1435
1611
  return makeKeyed(op, options.key ?? ((i) => i), options.perKey ?? "exclusive", timeoutOptions);
1612
+ }
1436
1613
  }
1437
1614
  }
1438
1615
  Op2.interpret = interpret;
@@ -1442,22 +1619,18 @@ var Op;
1442
1619
  var Optional;
1443
1620
  ((Optional2) => {
1444
1621
  Optional2.make = (get2, set2) => ({ get: get2, set: set2 });
1445
- Optional2.prop = () => (key) => (0, Optional2.make)(
1446
- (s) => {
1447
- const val = s[key];
1448
- return val !== null && val !== void 0 ? Maybe.some(val) : Maybe.none();
1449
- },
1450
- (a) => (s) => ({ ...s, [key]: a })
1451
- );
1452
- Optional2.index = (i) => (0, Optional2.make)(
1453
- (arr) => i >= 0 && i < arr.length ? Maybe.some(arr[i]) : Maybe.none(),
1454
- (a) => (arr) => {
1455
- if (i < 0 || i >= arr.length) return arr;
1456
- const copy = [...arr];
1457
- copy[i] = a;
1458
- return copy;
1459
- }
1460
- );
1622
+ Optional2.prop = () => (key) => (0, Optional2.make)((s) => {
1623
+ const val = s[key];
1624
+ return val !== null && val !== void 0 ? Maybe.some(val) : Maybe.none();
1625
+ }, (a) => (s) => ({ ...s, [key]: a }));
1626
+ Optional2.index = (i) => (0, Optional2.make)((arr) => i >= 0 && i < arr.length ? Maybe.some(arr[i]) : Maybe.none(), (a) => (arr) => {
1627
+ if (i < 0 || i >= arr.length) {
1628
+ return arr;
1629
+ }
1630
+ const copy = [...arr];
1631
+ copy[i] = a;
1632
+ return copy;
1633
+ });
1461
1634
  Optional2.get = (opt) => (s) => opt.get(s);
1462
1635
  Optional2.set = (opt) => (a) => (s) => opt.set(a)(s);
1463
1636
  Optional2.modify = (opt) => (f) => (s) => {
@@ -1476,26 +1649,20 @@ var Optional;
1476
1649
  const val = opt.get(s);
1477
1650
  return val.kind === "Some" ? cases.some(val.value) : cases.none();
1478
1651
  };
1479
- Optional2.andThen = (inner) => (outer) => (0, Optional2.make)(
1480
- (s) => {
1481
- const mid = outer.get(s);
1482
- return mid.kind === "None" ? Maybe.none() : inner.get(mid.value);
1483
- },
1484
- (b) => (s) => {
1485
- const mid = outer.get(s);
1486
- return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
1487
- }
1488
- );
1489
- Optional2.andThenLens = (inner) => (outer) => (0, Optional2.make)(
1490
- (s) => {
1491
- const mid = outer.get(s);
1492
- return mid.kind === "None" ? Maybe.none() : Maybe.some(inner.get(mid.value));
1493
- },
1494
- (b) => (s) => {
1495
- const mid = outer.get(s);
1496
- return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
1497
- }
1498
- );
1652
+ Optional2.andThen = (inner) => (outer) => (0, Optional2.make)((s) => {
1653
+ const mid = outer.get(s);
1654
+ return mid.kind === "None" ? Maybe.none() : inner.get(mid.value);
1655
+ }, (b) => (s) => {
1656
+ const mid = outer.get(s);
1657
+ return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
1658
+ });
1659
+ Optional2.andThenLens = (inner) => (outer) => (0, Optional2.make)((s) => {
1660
+ const mid = outer.get(s);
1661
+ return mid.kind === "None" ? Maybe.none() : Maybe.some(inner.get(mid.value));
1662
+ }, (b) => (s) => {
1663
+ const mid = outer.get(s);
1664
+ return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
1665
+ });
1499
1666
  })(Optional || (Optional = {}));
1500
1667
 
1501
1668
  // src/Core/Ordering.ts
@@ -1550,7 +1717,7 @@ var Refinement;
1550
1717
  Refinement2.and = (second) => (first) => (a) => first(a) && second(a);
1551
1718
  Refinement2.or = (second) => (first) => (a) => first(a) || second(a);
1552
1719
  Refinement2.toFilter = (r) => (a) => r(a) ? Maybe.some(a) : Maybe.none();
1553
- Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.error(onFail(a));
1720
+ Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.err(onFail(a));
1554
1721
  })(Refinement || (Refinement = {}));
1555
1722
 
1556
1723
  // src/Core/RemoteData.ts
@@ -1560,14 +1727,8 @@ var RemoteData;
1560
1727
  ((RemoteData2) => {
1561
1728
  RemoteData2.notAsked = () => _notAsked;
1562
1729
  RemoteData2.loading = () => _loading;
1563
- RemoteData2.failure = (error) => ({
1564
- kind: "Failure",
1565
- error
1566
- });
1567
- RemoteData2.success = (value) => ({
1568
- kind: "Success",
1569
- value
1570
- });
1730
+ RemoteData2.failure = (error) => ({ kind: "Failure", error });
1731
+ RemoteData2.success = (value) => ({ kind: "Success", value });
1571
1732
  RemoteData2.isNotAsked = (data) => data.kind === "NotAsked";
1572
1733
  RemoteData2.isLoading = (data) => data.kind === "Loading";
1573
1734
  RemoteData2.isFailure = (data) => data.kind === "Failure";
@@ -1579,80 +1740,73 @@ var RemoteData;
1579
1740
  if ((0, RemoteData2.isSuccess)(data) && (0, RemoteData2.isSuccess)(arg)) {
1580
1741
  return (0, RemoteData2.success)(data.value(arg.value));
1581
1742
  }
1582
- if ((0, RemoteData2.isFailure)(data)) return data;
1583
- if ((0, RemoteData2.isFailure)(arg)) return arg;
1584
- if ((0, RemoteData2.isLoading)(data) || (0, RemoteData2.isLoading)(arg)) return (0, RemoteData2.loading)();
1743
+ if ((0, RemoteData2.isFailure)(data)) {
1744
+ return data;
1745
+ }
1746
+ if ((0, RemoteData2.isFailure)(arg)) {
1747
+ return arg;
1748
+ }
1749
+ if ((0, RemoteData2.isLoading)(data) || (0, RemoteData2.isLoading)(arg)) {
1750
+ return (0, RemoteData2.loading)();
1751
+ }
1585
1752
  return (0, RemoteData2.notAsked)();
1586
1753
  };
1587
1754
  RemoteData2.fold = (onNotAsked, onLoading, onFailure, onSuccess) => (data) => {
1588
1755
  switch (data.kind) {
1589
- case "NotAsked":
1756
+ case "NotAsked": {
1590
1757
  return onNotAsked();
1591
- case "Loading":
1758
+ }
1759
+ case "Loading": {
1592
1760
  return onLoading();
1593
- case "Failure":
1761
+ }
1762
+ case "Failure": {
1594
1763
  return onFailure(data.error);
1595
- case "Success":
1764
+ }
1765
+ case "Success": {
1596
1766
  return onSuccess(data.value);
1767
+ }
1597
1768
  }
1598
1769
  };
1599
1770
  RemoteData2.match = (cases) => (data) => {
1600
1771
  switch (data.kind) {
1601
- case "NotAsked":
1772
+ case "NotAsked": {
1602
1773
  return cases.notAsked();
1603
- case "Loading":
1774
+ }
1775
+ case "Loading": {
1604
1776
  return cases.loading();
1605
- case "Failure":
1777
+ }
1778
+ case "Failure": {
1606
1779
  return cases.failure(data.error);
1607
- case "Success":
1780
+ }
1781
+ case "Success": {
1608
1782
  return cases.success(data.value);
1783
+ }
1609
1784
  }
1610
1785
  };
1611
1786
  RemoteData2.getOrElse = (defaultValue) => (data) => (0, RemoteData2.isSuccess)(data) ? data.value : defaultValue();
1612
1787
  RemoteData2.tap = (f) => (data) => {
1613
- if ((0, RemoteData2.isSuccess)(data)) f(data.value);
1788
+ if ((0, RemoteData2.isSuccess)(data)) {
1789
+ f(data.value);
1790
+ }
1614
1791
  return data;
1615
1792
  };
1616
1793
  RemoteData2.tapError = (f) => (data) => {
1617
- if ((0, RemoteData2.isFailure)(data)) f(data.error);
1794
+ if ((0, RemoteData2.isFailure)(data)) {
1795
+ f(data.error);
1796
+ }
1618
1797
  return data;
1619
1798
  };
1620
1799
  RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
1621
1800
  RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
1622
- RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.error((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
1801
+ RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
1623
1802
  RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
1624
1803
  RemoteData2.fromMaybe = (onNone) => (data) => Maybe.isSome(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(onNone());
1625
1804
  RemoteData2.filter = (pred, onFalse) => (data) => (0, RemoteData2.isSuccess)(data) ? pred(data.value) ? data : (0, RemoteData2.failure)(onFalse(data.value)) : data;
1626
1805
  })(RemoteData || (RemoteData = {}));
1627
1806
 
1628
- // src/Types/Brand.ts
1629
- var Brand;
1630
- ((Brand2) => {
1631
- Brand2.wrap = () => (value) => value;
1632
- Brand2.unwrap = (branded) => branded;
1633
- })(Brand || (Brand = {}));
1634
-
1635
- // src/Types/Duration.ts
1636
- var Duration;
1637
- ((Duration2) => {
1638
- const wrap = Brand.wrap();
1639
- Duration2.milliseconds = (ms) => wrap(ms);
1640
- Duration2.seconds = (s) => wrap(s * 1e3);
1641
- Duration2.minutes = (m) => wrap(m * 60 * 1e3);
1642
- Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
1643
- Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
1644
- Duration2.toMilliseconds = (d) => Brand.unwrap(d);
1645
- Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
1646
- Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
1647
- Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
1648
- Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
1649
- Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
1650
- Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
1651
- })(Duration || (Duration = {}));
1652
-
1653
1807
  // src/Core/Task.ts
1654
1808
  var toPromise = (task, signal) => Deferred.toPromise(task(signal));
1655
- var getMs = (ms) => typeof ms === "number" ? ms : Duration.toMilliseconds(ms);
1809
+ var getMs2 = (duration) => Duration.toMilliseconds(duration);
1656
1810
  var Task;
1657
1811
  ((Task2) => {
1658
1812
  Task2.resolve = (value) => () => Deferred.fromPromise(Promise.resolve(value));
@@ -1660,12 +1814,7 @@ var Task;
1660
1814
  Task2.fromSync = (f) => () => Deferred.fromPromise(Promise.resolve(f()));
1661
1815
  Task2.map = (f) => (data) => (0, Task2.from)((signal) => toPromise(data, signal).then(f));
1662
1816
  Task2.chain = (f) => (data) => (0, Task2.from)((signal) => toPromise(data, signal).then((a) => toPromise(f(a), signal)));
1663
- Task2.ap = (arg) => (data) => (0, Task2.from)(
1664
- (signal) => Promise.all([
1665
- toPromise(data, signal),
1666
- toPromise(arg, signal)
1667
- ]).then(([f, a]) => f(a))
1668
- );
1817
+ Task2.ap = (arg) => (data) => (0, Task2.from)((signal) => Promise.all([toPromise(data, signal), toPromise(arg, signal)]).then(([f, a]) => f(a)));
1669
1818
  Task2.tap = (f) => (data) => (0, Task2.from)(
1670
1819
  (signal) => toPromise(data, signal).then((a) => {
1671
1820
  f(a);
@@ -1675,35 +1824,39 @@ var Task;
1675
1824
  Task2.all = (tasks) => (0, Task2.from)(
1676
1825
  (signal) => Promise.all(tasks.map((t) => toPromise(t, signal)))
1677
1826
  );
1678
- Task2.delay = (ms) => (data) => (0, Task2.from)(
1679
- (signal) => new Promise((resolve2) => {
1680
- let timerId = void 0;
1827
+ Task2.delay = (duration) => (data) => (0, Task2.from)(
1828
+ (signal) => new Promise((res) => {
1829
+ let timerId;
1681
1830
  const onAbort = () => {
1682
1831
  if (timerId !== void 0) {
1683
1832
  clearTimeout(timerId);
1684
1833
  }
1685
- resolve2(toPromise(data, signal));
1834
+ res(toPromise(data, signal));
1686
1835
  };
1687
1836
  if (signal) {
1688
1837
  if (signal.aborted) {
1689
- return resolve2(toPromise(data, signal));
1838
+ return res(toPromise(data, signal));
1690
1839
  }
1691
1840
  signal.addEventListener("abort", onAbort, { once: true });
1692
1841
  }
1693
1842
  timerId = setTimeout(() => {
1694
1843
  signal?.removeEventListener("abort", onAbort);
1695
- resolve2(toPromise(data, signal));
1696
- }, getMs(ms));
1844
+ res(toPromise(data, signal));
1845
+ }, getMs2(duration));
1697
1846
  })
1698
1847
  );
1699
1848
  Task2.repeat = (options) => (task) => (0, Task2.from)((signal) => {
1700
- const { times, delay: ms } = options;
1701
- if (times <= 0) return Promise.resolve([]);
1849
+ const { times, delay: delayDuration } = options;
1850
+ if (times <= 0) {
1851
+ return Promise.resolve([]);
1852
+ }
1702
1853
  const results = [];
1703
1854
  const wait = () => {
1704
- if (signal?.aborted) return Promise.resolve();
1855
+ if (signal?.aborted) {
1856
+ return Promise.resolve();
1857
+ }
1705
1858
  return new Promise((r) => {
1706
- let timerId = void 0;
1859
+ let timerId;
1707
1860
  const onAbort = () => {
1708
1861
  if (timerId !== void 0) {
1709
1862
  clearTimeout(timerId);
@@ -1716,7 +1869,7 @@ var Task;
1716
1869
  timerId = setTimeout(() => {
1717
1870
  signal?.removeEventListener("abort", onAbort);
1718
1871
  r();
1719
- }, getMs(ms || 0));
1872
+ }, delayDuration ? getMs2(delayDuration) : 0);
1720
1873
  });
1721
1874
  };
1722
1875
  const run2 = (left) => {
@@ -1725,18 +1878,22 @@ var Task;
1725
1878
  }
1726
1879
  return toPromise(task, signal).then((a) => {
1727
1880
  results.push(a);
1728
- if (left <= 1 || signal?.aborted) return results;
1881
+ if (left <= 1 || signal?.aborted) {
1882
+ return results;
1883
+ }
1729
1884
  return wait().then(() => run2(left - 1));
1730
1885
  });
1731
1886
  };
1732
1887
  return run2(times);
1733
1888
  });
1734
1889
  Task2.repeatUntil = (options) => (task) => (0, Task2.from)((signal) => {
1735
- const { when: predicate, delay: ms, maxAttempts } = options;
1890
+ const { when: predicate, delay: delayDuration, maxAttempts } = options;
1736
1891
  const wait = () => {
1737
- if (signal?.aborted) return Promise.resolve();
1892
+ if (signal?.aborted) {
1893
+ return Promise.resolve();
1894
+ }
1738
1895
  return new Promise((r) => {
1739
- let timerId = void 0;
1896
+ let timerId;
1740
1897
  const onAbort = () => {
1741
1898
  if (timerId !== void 0) {
1742
1899
  clearTimeout(timerId);
@@ -1749,7 +1906,7 @@ var Task;
1749
1906
  timerId = setTimeout(() => {
1750
1907
  signal?.removeEventListener("abort", onAbort);
1751
1908
  r();
1752
- }, getMs(ms || 0));
1909
+ }, delayDuration ? getMs2(delayDuration) : 0);
1753
1910
  });
1754
1911
  };
1755
1912
  const run2 = (attempt, lastValue) => {
@@ -1757,9 +1914,15 @@ var Task;
1757
1914
  return Promise.resolve(lastValue);
1758
1915
  }
1759
1916
  return toPromise(task, signal).then((a) => {
1760
- if (predicate(a)) return a;
1761
- if (maxAttempts !== void 0 && attempt >= maxAttempts) return a;
1762
- if (signal?.aborted) return a;
1917
+ if (predicate(a)) {
1918
+ return a;
1919
+ }
1920
+ if (maxAttempts !== void 0 && attempt >= maxAttempts) {
1921
+ return a;
1922
+ }
1923
+ if (signal?.aborted) {
1924
+ return a;
1925
+ }
1763
1926
  return wait().then(() => run2(attempt + 1, a));
1764
1927
  });
1765
1928
  };
@@ -1773,7 +1936,9 @@ var Task;
1773
1936
  return (0, Task2.from)((outerSignal) => {
1774
1937
  const controllers = tasks.map(() => new AbortController());
1775
1938
  const onOuterAbort = () => {
1776
- for (const ctrl of controllers) ctrl.abort();
1939
+ for (const ctrl of controllers) {
1940
+ ctrl.abort();
1941
+ }
1777
1942
  };
1778
1943
  if (outerSignal) {
1779
1944
  if (outerSignal.aborted) {
@@ -1808,19 +1973,19 @@ var Task;
1808
1973
  }
1809
1974
  return results;
1810
1975
  });
1811
- Task2.timeout = (ms, onTimeout) => (task) => (0, Task2.from)((outerSignal) => {
1976
+ Task2.timeout = (duration, onTimeout) => (task) => (0, Task2.from)((outerSignal) => {
1812
1977
  const controller = new AbortController();
1813
1978
  let timerId;
1814
- const cleanUp = () => {
1979
+ function cleanUp() {
1815
1980
  if (timerId !== void 0) {
1816
1981
  clearTimeout(timerId);
1817
1982
  }
1818
1983
  outerSignal?.removeEventListener("abort", onOuterAbort);
1819
- };
1820
- const onOuterAbort = () => {
1984
+ }
1985
+ function onOuterAbort() {
1821
1986
  cleanUp();
1822
1987
  controller.abort();
1823
- };
1988
+ }
1824
1989
  if (outerSignal) {
1825
1990
  if (outerSignal.aborted) {
1826
1991
  controller.abort();
@@ -1833,12 +1998,12 @@ var Task;
1833
1998
  cleanUp();
1834
1999
  return Result.ok(a);
1835
2000
  }),
1836
- new Promise((resolve2) => {
2001
+ new Promise((res) => {
1837
2002
  timerId = setTimeout(() => {
1838
2003
  controller.abort();
1839
2004
  cleanUp();
1840
- resolve2(Result.error(onTimeout()));
1841
- }, getMs(ms));
2005
+ res(Result.err(onTimeout()));
2006
+ }, getMs2(duration));
1842
2007
  })
1843
2008
  ]);
1844
2009
  });
@@ -1866,14 +2031,19 @@ var Task;
1866
2031
  // src/Core/Resource.ts
1867
2032
  var Resource;
1868
2033
  ((Resource2) => {
1869
- Resource2.make = (acquire, release) => ({ acquire, release });
2034
+ Resource2.make = (acquire, release) => ({
2035
+ acquire,
2036
+ release
2037
+ });
1870
2038
  Resource2.fromTask = (acquire, release) => ({
1871
2039
  acquire: Task.map((a) => Result.ok(a))(acquire),
1872
2040
  release
1873
2041
  });
1874
2042
  Resource2.use = (f) => (resource) => Task.from(
1875
2043
  (signal) => Deferred.toPromise(resource.acquire(signal)).then(async (acquired) => {
1876
- if (Result.isError(acquired)) return acquired;
2044
+ if (Result.isErr(acquired)) {
2045
+ return acquired;
2046
+ }
1877
2047
  const a = acquired.value;
1878
2048
  try {
1879
2049
  const usageResult = await Deferred.toPromise(f(a)(signal));
@@ -1886,10 +2056,12 @@ var Resource;
1886
2056
  Resource2.combine = (resourceA, resourceB) => ({
1887
2057
  acquire: Task.from(
1888
2058
  (signal) => Deferred.toPromise(resourceA.acquire(signal)).then(async (acquiredA) => {
1889
- if (Result.isError(acquiredA)) return acquiredA;
2059
+ if (Result.isErr(acquiredA)) {
2060
+ return acquiredA;
2061
+ }
1890
2062
  const a = acquiredA.value;
1891
2063
  const acquiredB = await Deferred.toPromise(resourceB.acquire(signal));
1892
- if (Result.isError(acquiredB)) {
2064
+ if (Result.isErr(acquiredB)) {
1893
2065
  await Deferred.toPromise(resourceA.release(a)(signal));
1894
2066
  return acquiredB;
1895
2067
  }
@@ -1942,16 +2114,13 @@ var TaskMaybe;
1942
2114
  TaskMaybe2.fromNullable = (value) => Task.resolve(Maybe.fromNullable(value));
1943
2115
  TaskMaybe2.fromResult = (result) => Task.resolve(Result.toMaybe(result));
1944
2116
  TaskMaybe2.fromTask = (task) => Task.map(Maybe.some)(task);
1945
- TaskMaybe2.tryCatch = (f) => Task.from(
1946
- (signal) => f(signal).then(Maybe.some).catch(() => Maybe.none())
1947
- );
2117
+ TaskMaybe2.tryCatch = (f) => Task.from((signal) => f(signal).then(Maybe.some).catch(() => Maybe.none()));
1948
2118
  TaskMaybe2.map = (f) => (data) => Task.map(Maybe.map(f))(data);
1949
2119
  TaskMaybe2.chain = (f) => (data) => Task.chain((option) => Maybe.isSome(option) ? f(option.value) : Task.resolve(Maybe.none()))(data);
1950
2120
  TaskMaybe2.ap = (arg) => (data) => Task.from(
1951
- (signal) => Promise.all([
1952
- Deferred.toPromise(data(signal)),
1953
- Deferred.toPromise(arg(signal))
1954
- ]).then(([of_, oa]) => Maybe.ap(oa)(of_))
2121
+ (signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
2122
+ ([of_, oa]) => Maybe.ap(oa)(of_)
2123
+ )
1955
2124
  );
1956
2125
  TaskMaybe2.fold = (onNone, onSome) => (data) => Task.map(Maybe.fold(onNone, onSome))(data);
1957
2126
  TaskMaybe2.match = (cases) => (data) => Task.map(Maybe.match(cases))(data);
@@ -1965,36 +2134,29 @@ var TaskMaybe;
1965
2134
  var TaskResult;
1966
2135
  ((TaskResult2) => {
1967
2136
  TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
1968
- TaskResult2.err = (error) => Task.resolve(Result.error(error));
1969
- TaskResult2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.error(onNull()) : Result.ok(value));
1970
- TaskResult2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.error(onNone()) : Result.ok(maybe.value));
2137
+ TaskResult2.err = (error) => Task.resolve(Result.err(error));
2138
+ TaskResult2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.err(onNull()) : Result.ok(value));
2139
+ TaskResult2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.err(onNone()) : Result.ok(maybe.value));
1971
2140
  TaskResult2.fromResult = (result) => Task.resolve(result);
1972
- TaskResult2.fromThrowable = (f, onError) => (...args) => Task.from(
1973
- () => f(...args).then(Result.ok).catch((e) => Result.error(onError(e)))
1974
- );
1975
- TaskResult2.tryCatch = (f, onError) => Task.from(
1976
- (signal) => f(signal).then(Result.ok).catch((e) => Result.error(onError(e)))
1977
- );
2141
+ TaskResult2.fromThrowable = (f, onError) => (...args) => Task.from(() => f(...args).then(Result.ok).catch((error) => Result.err(onError(error))));
2142
+ TaskResult2.tryCatch = (f, onError) => Task.from((signal) => f(signal).then(Result.ok).catch((error) => Result.err(onError(error))));
1978
2143
  TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
1979
2144
  TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
1980
- TaskResult2.chain = (f) => (data) => Task.chain(
1981
- (result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.error(result.error))
1982
- )(
2145
+ TaskResult2.chain = (f) => (data) => Task.chain((result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.err(result.error)))(
1983
2146
  data
1984
2147
  );
1985
2148
  TaskResult2.fold = (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data);
1986
2149
  TaskResult2.match = (cases) => (data) => Task.map(Result.match(cases))(data);
1987
2150
  TaskResult2.recover = (fallback) => (data) => Task.chain(
1988
- (result) => Result.isError(result) ? fallback(result.error) : Task.resolve(result)
2151
+ (result) => Result.isErr(result) ? fallback(result.error) : Task.resolve(result)
1989
2152
  )(data);
1990
2153
  TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
1991
2154
  TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
1992
2155
  TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
1993
2156
  TaskResult2.ap = (arg) => (data) => Task.from(
1994
- (signal) => Promise.all([
1995
- Deferred.toPromise(data(signal)),
1996
- Deferred.toPromise(arg(signal))
1997
- ]).then(([of_, oa]) => Result.ap(oa)(of_))
2157
+ (signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
2158
+ ([of_, oa]) => Result.ap(oa)(of_)
2159
+ )
1998
2160
  );
1999
2161
  TaskResult2.run = (signal) => (task) => Deferred.toPromise(task(signal));
2000
2162
  })(TaskResult || (TaskResult = {}));
@@ -2002,102 +2164,97 @@ var TaskResult;
2002
2164
  // src/Core/Validation.ts
2003
2165
  var Validation;
2004
2166
  ((Validation2) => {
2005
- Validation2.valid = (value) => ({
2006
- kind: "Valid",
2007
- value
2008
- });
2009
- Validation2.invalid = (error) => ({
2010
- kind: "Invalid",
2011
- errors: [error]
2012
- });
2013
- Validation2.invalidAll = (errors) => ({
2014
- kind: "Invalid",
2015
- errors
2016
- });
2017
- Validation2.isValid = (data) => data.kind === "Valid";
2018
- Validation2.isInvalid = (data) => data.kind === "Invalid";
2019
- Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
2020
- Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.invalid)(onNull()) : (0, Validation2.valid)(value);
2021
- Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.invalid)(onNone()) : (0, Validation2.valid)(maybe.value);
2022
- Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
2167
+ Validation2.passed = (value) => ({ kind: "Passed", value });
2168
+ Validation2.failed = (error) => ({ kind: "Failed", errors: [error] });
2169
+ Validation2.failedAll = (errors) => ({ kind: "Failed", errors });
2170
+ Validation2.isPassed = (data) => data.kind === "Passed";
2171
+ Validation2.isFailed = (data) => data.kind === "Failed";
2172
+ Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.passed)(a) : (0, Validation2.failed)(onFalse(a));
2173
+ Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.failed)(onNull()) : (0, Validation2.passed)(value);
2174
+ Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.failed)(onNone()) : (0, Validation2.passed)(maybe.value);
2175
+ Validation2.map = (f) => (data) => (0, Validation2.isPassed)(data) ? (0, Validation2.passed)(f(data.value)) : data;
2176
+ Validation2.mapError = (f) => (data) => (0, Validation2.isFailed)(data) ? (0, Validation2.failedAll)(data.errors.map(f)) : data;
2023
2177
  Validation2.ap = (arg) => (data) => {
2024
- if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
2025
- const errors = [
2026
- ...(0, Validation2.isInvalid)(data) ? data.errors : [],
2027
- ...(0, Validation2.isInvalid)(arg) ? arg.errors : []
2028
- ];
2029
- return (0, Validation2.invalidAll)(errors);
2030
- };
2031
- Validation2.fold = (onInvalid, onValid) => (data) => (0, Validation2.isValid)(data) ? onValid(data.value) : onInvalid(data.errors);
2032
- Validation2.match = (cases) => (data) => (0, Validation2.isValid)(data) ? cases.valid(data.value) : cases.invalid(data.errors);
2033
- Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isValid)(data) ? data.value : defaultValue();
2178
+ if ((0, Validation2.isPassed)(data) && (0, Validation2.isPassed)(arg)) {
2179
+ return (0, Validation2.passed)(data.value(arg.value));
2180
+ }
2181
+ const errors = [...(0, Validation2.isFailed)(data) ? data.errors : [], ...(0, Validation2.isFailed)(arg) ? arg.errors : []];
2182
+ return (0, Validation2.failedAll)(errors);
2183
+ };
2184
+ Validation2.fold = (onFailed, onPassed) => (data) => (0, Validation2.isPassed)(data) ? onPassed(data.value) : onFailed(data.errors);
2185
+ Validation2.match = (cases) => (data) => (0, Validation2.isPassed)(data) ? cases.passed(data.value) : cases.failed(data.errors);
2186
+ Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isPassed)(data) ? data.value : defaultValue();
2034
2187
  Validation2.tap = (f) => (data) => {
2035
- if ((0, Validation2.isValid)(data)) f(data.value);
2188
+ if ((0, Validation2.isPassed)(data)) {
2189
+ f(data.value);
2190
+ }
2036
2191
  return data;
2037
2192
  };
2038
2193
  Validation2.tapError = (f) => (data) => {
2039
- if ((0, Validation2.isInvalid)(data)) f(data.errors);
2194
+ if ((0, Validation2.isFailed)(data)) {
2195
+ f(data.errors);
2196
+ }
2040
2197
  return data;
2041
2198
  };
2042
- Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
2043
- Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some(isBlocked) ? fallback() : data;
2044
- Validation2.toResult = (data) => (0, Validation2.isValid)(data) ? Result.ok(data.value) : Result.error(data.errors);
2045
- Validation2.toMaybe = (data) => (0, Validation2.isValid)(data) ? Maybe.some(data.value) : Maybe.none();
2046
- Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.valid)(data.value) : (0, Validation2.invalid)(data.error);
2199
+ Validation2.recover = (fallback) => (data) => (0, Validation2.isPassed)(data) ? data : fallback(data.errors);
2200
+ Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isFailed)(data) && !data.errors.some(isBlocked) ? fallback() : data;
2201
+ Validation2.toResult = (data) => (0, Validation2.isPassed)(data) ? Result.ok(data.value) : Result.err(data.errors);
2202
+ Validation2.toMaybe = (data) => (0, Validation2.isPassed)(data) ? Maybe.some(data.value) : Maybe.none();
2203
+ Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.passed)(data.value) : (0, Validation2.failed)(data.error);
2047
2204
  Validation2.product = (first, second) => {
2048
- if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
2049
- const errors = [
2050
- ...(0, Validation2.isInvalid)(first) ? first.errors : [],
2051
- ...(0, Validation2.isInvalid)(second) ? second.errors : []
2052
- ];
2053
- return (0, Validation2.invalidAll)(errors);
2205
+ if ((0, Validation2.isPassed)(first) && (0, Validation2.isPassed)(second)) {
2206
+ return (0, Validation2.passed)([first.value, second.value]);
2207
+ }
2208
+ const errors = [...(0, Validation2.isFailed)(first) ? first.errors : [], ...(0, Validation2.isFailed)(second) ? second.errors : []];
2209
+ return (0, Validation2.failedAll)(errors);
2054
2210
  };
2055
2211
  Validation2.productAll = (data) => {
2056
2212
  const values = [];
2057
2213
  const errors = [];
2058
2214
  for (const v of data) {
2059
- if ((0, Validation2.isValid)(v)) values.push(v.value);
2060
- else errors.push(...v.errors);
2215
+ if ((0, Validation2.isPassed)(v)) {
2216
+ values.push(v.value);
2217
+ } else {
2218
+ errors.push(...v.errors);
2219
+ }
2061
2220
  }
2062
- return errors.length > 0 ? (0, Validation2.invalidAll)(errors) : (0, Validation2.valid)(values);
2221
+ return errors.length > 0 ? (0, Validation2.failedAll)(errors) : (0, Validation2.passed)(values);
2063
2222
  };
2064
2223
  })(Validation || (Validation = {}));
2065
2224
 
2066
2225
  // src/Core/TaskValidation.ts
2067
2226
  var TaskValidation;
2068
2227
  ((TaskValidation2) => {
2069
- TaskValidation2.valid = (value) => Task.resolve(Validation.valid(value));
2070
- TaskValidation2.invalid = (error) => Task.resolve(Validation.invalid(error));
2071
- TaskValidation2.invalidAll = (errors) => Task.resolve(Validation.invalidAll(errors));
2228
+ TaskValidation2.passed = (value) => Task.resolve(Validation.passed(value));
2229
+ TaskValidation2.failed = (error) => Task.resolve(Validation.failed(error));
2230
+ TaskValidation2.failedAll = (errors) => Task.resolve(Validation.failedAll(errors));
2072
2231
  TaskValidation2.fromValidation = (validation) => Task.resolve(validation);
2073
- TaskValidation2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.invalid(onNull()) : Validation.valid(value));
2074
- TaskValidation2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Validation.invalid(onNone()) : Validation.valid(maybe.value));
2232
+ TaskValidation2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.failed(onNull()) : Validation.passed(value));
2233
+ TaskValidation2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Validation.failed(onNone()) : Validation.passed(maybe.value));
2075
2234
  TaskValidation2.fromResult = (result) => Task.resolve(Validation.fromResult(result));
2076
- TaskValidation2.tryCatch = (f, onError) => Task.from(
2077
- (signal) => f(signal).then(Validation.valid).catch((e) => Validation.invalid(onError(e)))
2078
- );
2235
+ TaskValidation2.tryCatch = (f, onError) => Task.from((signal) => f(signal).then(Validation.passed).catch((error) => Validation.failed(onError(error))));
2079
2236
  TaskValidation2.map = (f) => (data) => Task.map(Validation.map(f))(data);
2080
2237
  TaskValidation2.ap = (arg) => (data) => Task.from(
2081
- (signal) => Promise.all([
2082
- Deferred.toPromise(data(signal)),
2083
- Deferred.toPromise(arg(signal))
2084
- ]).then(([vf, va]) => Validation.ap(va)(vf))
2238
+ (signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
2239
+ ([vf, va]) => Validation.ap(va)(vf)
2240
+ )
2085
2241
  );
2086
- TaskValidation2.fold = (onInvalid, onValid) => (data) => Task.map(Validation.fold(onInvalid, onValid))(data);
2242
+ TaskValidation2.fold = (onFailed, onPassed) => (data) => Task.map(Validation.fold(onFailed, onPassed))(data);
2087
2243
  TaskValidation2.match = (cases) => (data) => Task.map(Validation.match(cases))(data);
2088
2244
  TaskValidation2.getOrElse = (defaultValue) => (data) => Task.map(Validation.getOrElse(defaultValue))(data);
2089
2245
  TaskValidation2.tap = (f) => (data) => Task.map(Validation.tap(f))(data);
2090
2246
  TaskValidation2.recover = (fallback) => (data) => Task.chain(
2091
- (validation) => Validation.isValid(validation) ? Task.resolve(validation) : fallback(validation.errors)
2247
+ (validation) => Validation.isPassed(validation) ? Task.resolve(validation) : fallback(validation.errors)
2092
2248
  )(data);
2093
2249
  TaskValidation2.product = (first, second) => Task.from(
2094
- (signal) => Promise.all([
2095
- Deferred.toPromise(first(signal)),
2096
- Deferred.toPromise(second(signal))
2097
- ]).then(([va, vb]) => Validation.product(va, vb))
2250
+ (signal) => Promise.all([Deferred.toPromise(first(signal)), Deferred.toPromise(second(signal))]).then(
2251
+ ([va, vb]) => Validation.product(va, vb)
2252
+ )
2098
2253
  );
2099
2254
  TaskValidation2.productAll = (data) => Task.from(
2100
- (signal) => Promise.all(data.map((t) => Deferred.toPromise(t(signal)))).then((results) => Validation.productAll(results))
2255
+ (signal) => Promise.all(data.map((t) => Deferred.toPromise(t(signal)))).then(
2256
+ (results) => Validation.productAll(results)
2257
+ )
2101
2258
  );
2102
2259
  })(TaskValidation || (TaskValidation = {}));
2103
2260
 
@@ -2106,58 +2263,84 @@ var These;
2106
2263
  ((These2) => {
2107
2264
  These2.first = (value) => ({ kind: "First", first: value });
2108
2265
  These2.second = (value) => ({ kind: "Second", second: value });
2109
- These2.both = (first2, second2) => ({
2110
- kind: "Both",
2111
- first: first2,
2112
- second: second2
2113
- });
2266
+ These2.both = (f, s) => ({ kind: "Both", first: f, second: s });
2114
2267
  These2.isFirst = (data) => data.kind === "First";
2115
2268
  These2.isSecond = (data) => data.kind === "Second";
2116
2269
  These2.isBoth = (data) => data.kind === "Both";
2117
2270
  These2.hasFirst = (data) => data.kind === "First" || data.kind === "Both";
2118
2271
  These2.hasSecond = (data) => data.kind === "Second" || data.kind === "Both";
2119
2272
  These2.mapFirst = (f) => (data) => {
2120
- if ((0, These2.isSecond)(data)) return data;
2121
- if ((0, These2.isFirst)(data)) return (0, These2.first)(f(data.first));
2273
+ if ((0, These2.isSecond)(data)) {
2274
+ return data;
2275
+ }
2276
+ if ((0, These2.isFirst)(data)) {
2277
+ return (0, These2.first)(f(data.first));
2278
+ }
2122
2279
  return (0, These2.both)(f(data.first), data.second);
2123
2280
  };
2124
2281
  These2.mapSecond = (f) => (data) => {
2125
- if ((0, These2.isFirst)(data)) return data;
2126
- if ((0, These2.isSecond)(data)) return (0, These2.second)(f(data.second));
2282
+ if ((0, These2.isFirst)(data)) {
2283
+ return data;
2284
+ }
2285
+ if ((0, These2.isSecond)(data)) {
2286
+ return (0, These2.second)(f(data.second));
2287
+ }
2127
2288
  return (0, These2.both)(data.first, f(data.second));
2128
2289
  };
2129
2290
  These2.mapBoth = (onFirst, onSecond) => (data) => {
2130
- if ((0, These2.isSecond)(data)) return (0, These2.second)(onSecond(data.second));
2131
- if ((0, These2.isFirst)(data)) return (0, These2.first)(onFirst(data.first));
2291
+ if ((0, These2.isSecond)(data)) {
2292
+ return (0, These2.second)(onSecond(data.second));
2293
+ }
2294
+ if ((0, These2.isFirst)(data)) {
2295
+ return (0, These2.first)(onFirst(data.first));
2296
+ }
2132
2297
  return (0, These2.both)(onFirst(data.first), onSecond(data.second));
2133
2298
  };
2134
2299
  These2.chainFirst = (f) => (data) => {
2135
- if ((0, These2.isSecond)(data)) return data;
2300
+ if ((0, These2.isSecond)(data)) {
2301
+ return data;
2302
+ }
2136
2303
  return f(data.first);
2137
2304
  };
2138
2305
  These2.chainSecond = (f) => (data) => {
2139
- if ((0, These2.isFirst)(data)) return data;
2306
+ if ((0, These2.isFirst)(data)) {
2307
+ return data;
2308
+ }
2140
2309
  return f(data.second);
2141
2310
  };
2142
2311
  These2.fold = (onFirst, onSecond, onBoth) => (data) => {
2143
- if ((0, These2.isSecond)(data)) return onSecond(data.second);
2144
- if ((0, These2.isFirst)(data)) return onFirst(data.first);
2312
+ if ((0, These2.isSecond)(data)) {
2313
+ return onSecond(data.second);
2314
+ }
2315
+ if ((0, These2.isFirst)(data)) {
2316
+ return onFirst(data.first);
2317
+ }
2145
2318
  return onBoth(data.first, data.second);
2146
2319
  };
2147
2320
  These2.match = (cases) => (data) => {
2148
- if ((0, These2.isSecond)(data)) return cases.second(data.second);
2149
- if ((0, These2.isFirst)(data)) return cases.first(data.first);
2321
+ if ((0, These2.isSecond)(data)) {
2322
+ return cases.second(data.second);
2323
+ }
2324
+ if ((0, These2.isFirst)(data)) {
2325
+ return cases.first(data.first);
2326
+ }
2150
2327
  return cases.both(data.first, data.second);
2151
2328
  };
2152
2329
  These2.getFirstOrElse = (defaultValue) => (data) => (0, These2.hasFirst)(data) ? data.first : defaultValue();
2153
2330
  These2.getSecondOrElse = (defaultValue) => (data) => (0, These2.hasSecond)(data) ? data.second : defaultValue();
2154
2331
  These2.tap = (f) => (data) => {
2155
- if ((0, These2.hasFirst)(data)) f(data.first);
2332
+ if ((0, These2.hasFirst)(data)) {
2333
+ f(data.first);
2334
+ }
2156
2335
  return data;
2157
2336
  };
2158
2337
  These2.swap = (data) => {
2159
- if ((0, These2.isSecond)(data)) return (0, These2.first)(data.second);
2160
- if ((0, These2.isFirst)(data)) return (0, These2.second)(data.first);
2338
+ if ((0, These2.isSecond)(data)) {
2339
+ return (0, These2.first)(data.second);
2340
+ }
2341
+ if ((0, These2.isFirst)(data)) {
2342
+ return (0, These2.second)(data.first);
2343
+ }
2161
2344
  return (0, These2.both)(data.second, data.first);
2162
2345
  };
2163
2346
  })(These || (These = {}));
@@ -2195,35 +2378,43 @@ var Arr;
2195
2378
  Arr2.init = (data) => data.length > 0 ? Maybe.some(data.slice(0, -1)) : Maybe.none();
2196
2379
  Arr2.findFirst = (predicate) => (data) => {
2197
2380
  const idx = data.findIndex(predicate);
2198
- return idx >= 0 ? Maybe.some(data[idx]) : Maybe.none();
2381
+ return idx !== -1 ? Maybe.some(data[idx]) : Maybe.none();
2199
2382
  };
2200
2383
  Arr2.findLast = (predicate) => (data) => {
2201
2384
  for (let i = data.length - 1; i >= 0; i--) {
2202
- if (predicate(data[i])) return Maybe.some(data[i]);
2385
+ if (predicate(data[i])) {
2386
+ return Maybe.some(data[i]);
2387
+ }
2203
2388
  }
2204
2389
  return Maybe.none();
2205
2390
  };
2206
2391
  Arr2.findIndex = (predicate) => (data) => {
2207
2392
  const idx = data.findIndex(predicate);
2208
- return idx >= 0 ? Maybe.some(idx) : Maybe.none();
2393
+ return idx !== -1 ? Maybe.some(idx) : Maybe.none();
2209
2394
  };
2210
2395
  Arr2.map = (f) => (data) => {
2211
2396
  const n = data.length;
2212
2397
  const result = new Array(n);
2213
- for (let i = 0; i < n; i++) result[i] = f(data[i]);
2398
+ for (let i = 0; i < n; i++) {
2399
+ result[i] = f(data[i]);
2400
+ }
2214
2401
  return result;
2215
2402
  };
2216
2403
  Arr2.mapWithIndex = (f) => (data) => {
2217
2404
  const n = data.length;
2218
2405
  const result = new Array(n);
2219
- for (let i = 0; i < n; i++) result[i] = f(i, data[i]);
2406
+ for (let i = 0; i < n; i++) {
2407
+ result[i] = f(i, data[i]);
2408
+ }
2220
2409
  return result;
2221
2410
  };
2222
2411
  Arr2.filter = (predicate) => (data) => {
2223
2412
  const n = data.length;
2224
2413
  const result = [];
2225
2414
  for (let i = 0; i < n; i++) {
2226
- if (predicate(data[i])) result.push(data[i]);
2415
+ if (predicate(data[i])) {
2416
+ result.push(data[i]);
2417
+ }
2227
2418
  }
2228
2419
  return result;
2229
2420
  };
@@ -2231,7 +2422,9 @@ var Arr;
2231
2422
  const result = [];
2232
2423
  for (let i = 0; i < data.length; i++) {
2233
2424
  const mapped = f(data[i]);
2234
- if (mapped.kind === "Some") result.push(mapped.value);
2425
+ if (mapped.kind === "Some") {
2426
+ result.push(mapped.value);
2427
+ }
2235
2428
  }
2236
2429
  return result;
2237
2430
  };
@@ -2281,14 +2474,14 @@ var Arr;
2281
2474
  const result = {};
2282
2475
  for (const a of data) {
2283
2476
  const key = f(a);
2284
- if (!result[key]) result[key] = [];
2477
+ if (!result[key]) {
2478
+ result[key] = [];
2479
+ }
2285
2480
  result[key].push(a);
2286
2481
  }
2287
2482
  return result;
2288
2483
  };
2289
- Arr2.uniq = (data) => [
2290
- ...new Set(data)
2291
- ];
2484
+ Arr2.uniq = (data) => [...new Set(data)];
2292
2485
  Arr2.uniqBy = (f) => (data) => {
2293
2486
  const seen = /* @__PURE__ */ new Set();
2294
2487
  const result = [];
@@ -2312,12 +2505,16 @@ var Arr;
2312
2505
  };
2313
2506
  Arr2.sortBy = (compare) => (data) => {
2314
2507
  const arr = data;
2315
- if (typeof arr.toSorted === "function") return arr.toSorted(compare);
2316
- return [...data].sort(compare);
2508
+ if (typeof arr.toSorted === "function") {
2509
+ return arr.toSorted(compare);
2510
+ }
2511
+ return [...data].toSorted(compare);
2317
2512
  };
2318
2513
  Arr2.sortWith = (ord) => (data) => {
2319
2514
  const arr = data;
2320
- if (typeof arr.toSorted === "function") return arr.toSorted(ord);
2515
+ if (typeof arr.toSorted === "function") {
2516
+ return arr.toSorted(ord);
2517
+ }
2321
2518
  return [...data].sort(ord);
2322
2519
  };
2323
2520
  Arr2.zip = (other) => (data) => {
@@ -2337,7 +2534,9 @@ var Arr;
2337
2534
  return result;
2338
2535
  };
2339
2536
  Arr2.intersperse = (sep) => (data) => {
2340
- if (data.length <= 1) return data;
2537
+ if (data.length <= 1) {
2538
+ return data;
2539
+ }
2341
2540
  const result = [data[0]];
2342
2541
  for (let i = 1; i < data.length; i++) {
2343
2542
  result.push(sep, data[i]);
@@ -2345,7 +2544,9 @@ var Arr;
2345
2544
  return result;
2346
2545
  };
2347
2546
  Arr2.chunksOf = (n) => (data) => {
2348
- if (n <= 0) return [];
2547
+ if (n <= 0) {
2548
+ return [];
2549
+ }
2349
2550
  const result = [];
2350
2551
  for (let i = 0; i < data.length; i += n) {
2351
2552
  result.push(data.slice(i, i + n));
@@ -2375,7 +2576,9 @@ var Arr;
2375
2576
  for (let i = 0; i < n; i++) {
2376
2577
  const chunk = f(data[i]);
2377
2578
  const m = chunk.length;
2378
- for (let j = 0; j < m; j++) result.push(chunk[j]);
2579
+ for (let j = 0; j < m; j++) {
2580
+ result.push(chunk[j]);
2581
+ }
2379
2582
  }
2380
2583
  return result;
2381
2584
  };
@@ -2385,7 +2588,9 @@ var Arr;
2385
2588
  const result = new Array(n);
2386
2589
  for (let i = 0; i < n; i++) {
2387
2590
  const mapped = f(data[i]);
2388
- if (mapped.kind === "None") return Maybe.none();
2591
+ if (mapped.kind === "None") {
2592
+ return Maybe.none();
2593
+ }
2389
2594
  result[i] = mapped.value;
2390
2595
  }
2391
2596
  return Maybe.some(result);
@@ -2395,7 +2600,9 @@ var Arr;
2395
2600
  const result = new Array(n);
2396
2601
  for (let i = 0; i < n; i++) {
2397
2602
  const mapped = f(data[i]);
2398
- if (mapped.kind === "Error") return mapped;
2603
+ if (mapped.kind === "Err") {
2604
+ return mapped;
2605
+ }
2399
2606
  result[i] = mapped.value;
2400
2607
  }
2401
2608
  return Result.ok(result);
@@ -2408,7 +2615,9 @@ var Arr;
2408
2615
  const result = [];
2409
2616
  for (const a of data) {
2410
2617
  const r = await Deferred.toPromise(f(a)());
2411
- if (Result.isError(r)) return r;
2618
+ if (Result.isErr(r)) {
2619
+ return r;
2620
+ }
2412
2621
  result.push(r.value);
2413
2622
  }
2414
2623
  return Result.ok(result);
@@ -2418,27 +2627,41 @@ var Arr;
2418
2627
  Arr2.size = (data) => data.length;
2419
2628
  Arr2.some = (predicate) => (data) => {
2420
2629
  const n = data.length;
2421
- for (let i = 0; i < n; i++) if (predicate(data[i])) return true;
2630
+ for (let i = 0; i < n; i++) {
2631
+ if (predicate(data[i])) {
2632
+ return true;
2633
+ }
2634
+ }
2422
2635
  return false;
2423
2636
  };
2424
2637
  Arr2.every = (predicate) => (data) => {
2425
2638
  const n = data.length;
2426
- for (let i = 0; i < n; i++) if (!predicate(data[i])) return false;
2639
+ for (let i = 0; i < n; i++) {
2640
+ if (!predicate(data[i])) {
2641
+ return false;
2642
+ }
2643
+ }
2427
2644
  return true;
2428
2645
  };
2429
- Arr2.reverse = (data) => [...data].reverse();
2646
+ Arr2.reverse = (data) => [...data].toReversed();
2430
2647
  Arr2.insertAt = (index, item) => (data) => {
2431
2648
  const i = Math.max(0, Math.min(index, data.length));
2432
2649
  const arr = data;
2433
- if (typeof arr.toSpliced === "function") return arr.toSpliced(i, 0, item);
2650
+ if (typeof arr.toSpliced === "function") {
2651
+ return arr.toSpliced(i, 0, item);
2652
+ }
2434
2653
  const result = [...data];
2435
2654
  result.splice(i, 0, item);
2436
2655
  return result;
2437
2656
  };
2438
2657
  Arr2.removeAt = (index) => (data) => {
2439
- if (index < 0 || index >= data.length) return data;
2658
+ if (index < 0 || index >= data.length) {
2659
+ return data;
2660
+ }
2440
2661
  const arr = data;
2441
- if (typeof arr.toSpliced === "function") return arr.toSpliced(index, 1);
2662
+ if (typeof arr.toSpliced === "function") {
2663
+ return arr.toSpliced(index, 1);
2664
+ }
2442
2665
  const result = [...data];
2443
2666
  result.splice(index, 1);
2444
2667
  return result;
@@ -2448,14 +2671,18 @@ var Arr;
2448
2671
  Arr2.takeWhile = (predicate) => (data) => {
2449
2672
  const result = [];
2450
2673
  for (const a of data) {
2451
- if (!predicate(a)) break;
2674
+ if (!predicate(a)) {
2675
+ break;
2676
+ }
2452
2677
  result.push(a);
2453
2678
  }
2454
2679
  return result;
2455
2680
  };
2456
2681
  Arr2.dropWhile = (predicate) => (data) => {
2457
2682
  let i = 0;
2458
- while (i < data.length && predicate(data[i])) i++;
2683
+ while (i < data.length && predicate(data[i])) {
2684
+ i++;
2685
+ }
2459
2686
  return data.slice(i);
2460
2687
  };
2461
2688
  Arr2.scan = (initial, f) => (data) => {
@@ -2486,8 +2713,11 @@ var Dict;
2486
2713
  for (const item of items) {
2487
2714
  const key = keyFn(item);
2488
2715
  const arr = result.get(key);
2489
- if (arr !== void 0) arr.push(item);
2490
- else result.set(key, [item]);
2716
+ if (arr !== void 0) {
2717
+ arr.push(item);
2718
+ } else {
2719
+ result.set(key, [item]);
2720
+ }
2491
2721
  }
2492
2722
  return result;
2493
2723
  };
@@ -2504,7 +2734,9 @@ var Dict;
2504
2734
  return result;
2505
2735
  };
2506
2736
  Dict2.remove = (key) => (m) => {
2507
- if (!m.has(key)) return m;
2737
+ if (!m.has(key)) {
2738
+ return m;
2739
+ }
2508
2740
  const result = new globalThis.Map(m);
2509
2741
  result.delete(key);
2510
2742
  return result;
@@ -2531,21 +2763,27 @@ var Dict;
2531
2763
  Dict2.filter = (predicate) => (m) => {
2532
2764
  const result = new globalThis.Map();
2533
2765
  for (const [k, v] of m) {
2534
- if (predicate(v)) result.set(k, v);
2766
+ if (predicate(v)) {
2767
+ result.set(k, v);
2768
+ }
2535
2769
  }
2536
2770
  return result;
2537
2771
  };
2538
2772
  Dict2.filterWithKey = (predicate) => (m) => {
2539
2773
  const result = new globalThis.Map();
2540
2774
  for (const [k, v] of m) {
2541
- if (predicate(k, v)) result.set(k, v);
2775
+ if (predicate(k, v)) {
2776
+ result.set(k, v);
2777
+ }
2542
2778
  }
2543
2779
  return result;
2544
2780
  };
2545
2781
  Dict2.compact = (m) => {
2546
2782
  const result = new globalThis.Map();
2547
2783
  for (const [k, v] of m) {
2548
- if (v.kind === "Some") result.set(k, v.value);
2784
+ if (v.kind === "Some") {
2785
+ result.set(k, v.value);
2786
+ }
2549
2787
  }
2550
2788
  return result;
2551
2789
  };
@@ -2553,7 +2791,9 @@ var Dict;
2553
2791
  const result = new globalThis.Map();
2554
2792
  for (const [key, value] of m) {
2555
2793
  const mapped = f(value);
2556
- if (mapped.kind === "Some") result.set(key, mapped.value);
2794
+ if (mapped.kind === "Some") {
2795
+ result.set(key, mapped.value);
2796
+ }
2557
2797
  }
2558
2798
  return result;
2559
2799
  };
@@ -2567,14 +2807,18 @@ var Dict;
2567
2807
  Dict2.intersection = (other) => (m) => {
2568
2808
  const result = new globalThis.Map();
2569
2809
  for (const [k, v] of m) {
2570
- if (other.has(k)) result.set(k, v);
2810
+ if (other.has(k)) {
2811
+ result.set(k, v);
2812
+ }
2571
2813
  }
2572
2814
  return result;
2573
2815
  };
2574
2816
  Dict2.difference = (other) => (m) => {
2575
2817
  const result = new globalThis.Map();
2576
2818
  for (const [k, v] of m) {
2577
- if (!other.has(k)) result.set(k, v);
2819
+ if (!other.has(k)) {
2820
+ result.set(k, v);
2821
+ }
2578
2822
  }
2579
2823
  return result;
2580
2824
  };
@@ -2599,7 +2843,9 @@ var Dict;
2599
2843
  var Num;
2600
2844
  ((Num2) => {
2601
2845
  Num2.range = (from, to, step = 1) => {
2602
- if (step <= 0 || from > to) return [];
2846
+ if (step <= 0 || from > to) {
2847
+ return [];
2848
+ }
2603
2849
  const count = Math.floor((to - from) / step) + 1;
2604
2850
  const result = new Array(count);
2605
2851
  for (let i = 0; i < count; i++) {
@@ -2610,7 +2856,9 @@ var Num;
2610
2856
  Num2.clamp = (min2, max2) => (n) => Math.min(Math.max(n, min2), max2);
2611
2857
  Num2.between = (min2, max2) => (n) => n >= min2 && n <= max2;
2612
2858
  Num2.parse = (s) => {
2613
- if (s.trim() === "") return Maybe.none();
2859
+ if (s.trim() === "") {
2860
+ return Maybe.none();
2861
+ }
2614
2862
  const n = Number(s);
2615
2863
  return isNaN(n) ? Maybe.none() : Maybe.some(n);
2616
2864
  };
@@ -2626,23 +2874,33 @@ var Num;
2626
2874
  Num2.remainder = (divisor) => (n) => divisor === 0 ? Maybe.none() : Maybe.some(n % divisor);
2627
2875
  Num2.sum = (ns) => {
2628
2876
  let result = 0;
2629
- for (let i = 0; i < ns.length; i++) result += ns[i];
2877
+ for (let i = 0; i < ns.length; i++) {
2878
+ result += ns[i];
2879
+ }
2630
2880
  return result;
2631
2881
  };
2632
2882
  Num2.mean = (ns) => ns.length === 0 ? Maybe.none() : Maybe.some((0, Num2.sum)(ns) / ns.length);
2633
2883
  Num2.min = (ns) => {
2634
- if (ns.length === 0) return Maybe.none();
2884
+ if (ns.length === 0) {
2885
+ return Maybe.none();
2886
+ }
2635
2887
  let [result] = ns;
2636
2888
  for (let i = 1; i < ns.length; i++) {
2637
- if (ns[i] < result) result = ns[i];
2889
+ if (ns[i] < result) {
2890
+ result = ns[i];
2891
+ }
2638
2892
  }
2639
2893
  return Maybe.some(result);
2640
2894
  };
2641
2895
  Num2.max = (ns) => {
2642
- if (ns.length === 0) return Maybe.none();
2896
+ if (ns.length === 0) {
2897
+ return Maybe.none();
2898
+ }
2643
2899
  let [result] = ns;
2644
2900
  for (let i = 1; i < ns.length; i++) {
2645
- if (ns[i] > result) result = ns[i];
2901
+ if (ns[i] > result) {
2902
+ result = ns[i];
2903
+ }
2646
2904
  }
2647
2905
  return Maybe.some(result);
2648
2906
  };
@@ -2654,16 +2912,33 @@ var Rec;
2654
2912
  Rec2.map = (f) => (data) => {
2655
2913
  const keys2 = Object.keys(data);
2656
2914
  const vals = Object.values(data);
2657
- const result = {};
2915
+ const result = Object.create(Object.getPrototypeOf(data));
2658
2916
  for (let i = 0; i < keys2.length; i++) {
2659
2917
  Object.defineProperty(result, keys2[i], { value: f(vals[i]), writable: true, enumerable: true, configurable: true });
2660
2918
  }
2661
2919
  return result;
2662
2920
  };
2921
+ Rec2.filterMap = (f) => (data) => {
2922
+ const keys2 = Object.keys(data);
2923
+ const vals = Object.values(data);
2924
+ const result = Object.create(Object.getPrototypeOf(data));
2925
+ for (let i = 0; i < keys2.length; i++) {
2926
+ const maybeVal = f(vals[i]);
2927
+ if (maybeVal.kind === "Some") {
2928
+ Object.defineProperty(result, keys2[i], {
2929
+ value: maybeVal.value,
2930
+ writable: true,
2931
+ enumerable: true,
2932
+ configurable: true
2933
+ });
2934
+ }
2935
+ }
2936
+ return result;
2937
+ };
2663
2938
  Rec2.mapWithKey = (f) => (data) => {
2664
2939
  const keys2 = Object.keys(data);
2665
2940
  const vals = Object.values(data);
2666
- const result = {};
2941
+ const result = Object.create(Object.getPrototypeOf(data));
2667
2942
  for (let i = 0; i < keys2.length; i++) {
2668
2943
  Object.defineProperty(result, keys2[i], {
2669
2944
  value: f(keys2[i], vals[i]),
@@ -2675,10 +2950,12 @@ var Rec;
2675
2950
  return result;
2676
2951
  };
2677
2952
  Rec2.filter = (predicate) => (data) => {
2678
- const result = {};
2679
- for (const [k, v] of Object.entries(data)) {
2680
- if (predicate(v)) {
2681
- Object.defineProperty(result, k, { value: v, writable: true, enumerable: true, configurable: true });
2953
+ const keys2 = Object.keys(data);
2954
+ const vals = Object.values(data);
2955
+ const result = Object.create(Object.getPrototypeOf(data));
2956
+ for (let i = 0; i < keys2.length; i++) {
2957
+ if (predicate(vals[i])) {
2958
+ Object.defineProperty(result, keys2[i], { value: vals[i], writable: true, enumerable: true, configurable: true });
2682
2959
  }
2683
2960
  }
2684
2961
  return result;
@@ -2811,8 +3088,8 @@ var Str;
2811
3088
  Str2.parseJson = (s) => {
2812
3089
  try {
2813
3090
  return Result.ok(JSON.parse(s));
2814
- } catch (e) {
2815
- return Result.error(e);
3091
+ } catch (error) {
3092
+ return Result.err(error);
2816
3093
  }
2817
3094
  };
2818
3095
  })(Str || (Str = {}));
@@ -2828,20 +3105,28 @@ var Uniq;
2828
3105
  Uniq2.isEmpty = (s) => s.size === 0;
2829
3106
  Uniq2.isSubsetOf = (other) => (s) => {
2830
3107
  const set = s;
2831
- if (typeof set.isSubsetOf === "function") return set.isSubsetOf(other);
3108
+ if (typeof set.isSubsetOf === "function") {
3109
+ return set.isSubsetOf(other);
3110
+ }
2832
3111
  for (const item of s) {
2833
- if (!other.has(item)) return false;
3112
+ if (!other.has(item)) {
3113
+ return false;
3114
+ }
2834
3115
  }
2835
3116
  return true;
2836
3117
  };
2837
3118
  Uniq2.insert = (item) => (s) => {
2838
- if (s.has(item)) return s;
3119
+ if (s.has(item)) {
3120
+ return s;
3121
+ }
2839
3122
  const result = new globalThis.Set(s);
2840
3123
  result.add(item);
2841
3124
  return result;
2842
3125
  };
2843
3126
  Uniq2.remove = (item) => (s) => {
2844
- if (!s.has(item)) return s;
3127
+ if (!s.has(item)) {
3128
+ return s;
3129
+ }
2845
3130
  const result = new globalThis.Set(s);
2846
3131
  result.delete(item);
2847
3132
  return result;
@@ -2856,29 +3141,47 @@ var Uniq;
2856
3141
  Uniq2.filter = (predicate) => (s) => {
2857
3142
  const result = new globalThis.Set();
2858
3143
  for (const item of s) {
2859
- if (predicate(item)) result.add(item);
3144
+ if (predicate(item)) {
3145
+ result.add(item);
3146
+ }
2860
3147
  }
2861
3148
  return result;
2862
3149
  };
2863
3150
  Uniq2.union = (other) => (s) => {
2864
3151
  const set = s;
2865
- if (typeof set.union === "function") return set.union(other);
3152
+ if (typeof set.union === "function") {
3153
+ return set.union(other);
3154
+ }
2866
3155
  const result = new globalThis.Set(s);
2867
- for (const item of other) result.add(item);
3156
+ for (const item of other) {
3157
+ result.add(item);
3158
+ }
2868
3159
  return result;
2869
3160
  };
2870
3161
  Uniq2.intersection = (other) => (s) => {
2871
3162
  const set = s;
2872
- if (typeof set.intersection === "function") return set.intersection(other);
3163
+ if (typeof set.intersection === "function") {
3164
+ return set.intersection(other);
3165
+ }
2873
3166
  const result = new globalThis.Set();
2874
- for (const item of s) if (other.has(item)) result.add(item);
3167
+ for (const item of s) {
3168
+ if (other.has(item)) {
3169
+ result.add(item);
3170
+ }
3171
+ }
2875
3172
  return result;
2876
3173
  };
2877
3174
  Uniq2.difference = (other) => (s) => {
2878
3175
  const set = s;
2879
- if (typeof set.difference === "function") return set.difference(other);
3176
+ if (typeof set.difference === "function") {
3177
+ return set.difference(other);
3178
+ }
2880
3179
  const result = new globalThis.Set();
2881
- for (const item of s) if (!other.has(item)) result.add(item);
3180
+ for (const item of s) {
3181
+ if (!other.has(item)) {
3182
+ result.add(item);
3183
+ }
3184
+ }
2882
3185
  return result;
2883
3186
  };
2884
3187
  Uniq2.reduce = (init, f) => (s) => {