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