@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/core.js CHANGED
@@ -51,35 +51,48 @@ module.exports = __toCommonJS(Core_exports);
51
51
  var Result;
52
52
  ((Result2) => {
53
53
  Result2.ok = (value) => ({ kind: "Ok", value });
54
- Result2.error = (e) => ({ kind: "Error", error: e });
54
+ Result2.err = (e) => ({ kind: "Err", error: e });
55
55
  Result2.isOk = (data) => data.kind === "Ok";
56
- Result2.isError = (data) => data.kind === "Error";
56
+ Result2.isErr = (data) => data.kind === "Err";
57
57
  Result2.tryCatch = (f, onError) => {
58
58
  try {
59
59
  return (0, Result2.ok)(f());
60
- } catch (e) {
61
- return (0, Result2.error)(onError(e));
60
+ } catch (error) {
61
+ return (0, Result2.err)(onError(error));
62
62
  }
63
63
  };
64
64
  Result2.map = (f) => (data) => (0, Result2.isOk)(data) ? (0, Result2.ok)(f(data.value)) : data;
65
- Result2.mapError = (f) => (data) => (0, Result2.isError)(data) ? (0, Result2.error)(f(data.error)) : data;
65
+ Result2.mapError = (f) => (data) => (0, Result2.isErr)(data) ? (0, Result2.err)(f(data.error)) : data;
66
66
  Result2.chain = (f) => (data) => (0, Result2.isOk)(data) ? f(data.value) : data;
67
67
  Result2.fold = (onErr, onOk) => (data) => (0, Result2.isOk)(data) ? onOk(data.value) : onErr(data.error);
68
68
  Result2.match = (cases) => (data) => (0, Result2.isOk)(data) ? cases.ok(data.value) : cases.err(data.error);
69
69
  Result2.getOrElse = (defaultValue) => (data) => (0, Result2.isOk)(data) ? data.value : defaultValue();
70
70
  Result2.tap = (f) => (data) => {
71
- if ((0, Result2.isOk)(data)) f(data.value);
71
+ if ((0, Result2.isOk)(data)) {
72
+ f(data.value);
73
+ }
72
74
  return data;
73
75
  };
74
76
  Result2.tapError = (f) => (data) => {
75
- if ((0, Result2.isError)(data)) f(data.error);
77
+ if ((0, Result2.isErr)(data)) {
78
+ f(data.error);
79
+ }
76
80
  return data;
77
81
  };
78
- Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.error)(onFalse(a));
82
+ Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.err)(onFalse(a));
83
+ Result2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Result2.err)(onNull()) : (0, Result2.ok)(value);
84
+ Result2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Result2.err)(onNone()) : (0, Result2.ok)(maybe.value);
85
+ Result2.fromThrowable = (f, onError) => (...args) => {
86
+ try {
87
+ return (0, Result2.ok)(f(...args));
88
+ } catch (error) {
89
+ return (0, Result2.err)(onError(error));
90
+ }
91
+ };
79
92
  Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
80
- Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isError)(data) && !isBlocked(data.error) ? fallback() : data;
93
+ Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isErr)(data) && !isBlocked(data.error) ? fallback() : data;
81
94
  Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
82
- 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;
95
+ 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;
83
96
  })(Result || (Result = {}));
84
97
 
85
98
  // src/Core/Maybe.ts
@@ -94,7 +107,7 @@ var Maybe;
94
107
  Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
95
108
  Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
96
109
  Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
97
- Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.error(onNone());
110
+ Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
98
111
  Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
99
112
  Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
100
113
  Maybe2.chain = (f) => (data) => (0, Maybe2.isSome)(data) ? f(data.value) : data;
@@ -102,7 +115,9 @@ var Maybe;
102
115
  Maybe2.match = (cases) => (data) => (0, Maybe2.isSome)(data) ? cases.some(data.value) : cases.none();
103
116
  Maybe2.getOrElse = (defaultValue) => (data) => (0, Maybe2.isSome)(data) ? data.value : defaultValue();
104
117
  Maybe2.tap = (f) => (data) => {
105
- if ((0, Maybe2.isSome)(data)) f(data.value);
118
+ if ((0, Maybe2.isSome)(data)) {
119
+ f(data.value);
120
+ }
106
121
  return data;
107
122
  };
108
123
  Maybe2.filter = (predicate) => (data) => (0, Maybe2.isSome)(data) ? predicate(data.value) ? data : (0, Maybe2.none)() : data;
@@ -113,30 +128,12 @@ var Maybe;
113
128
  // src/Core/Combinable.ts
114
129
  var Combinable;
115
130
  ((Combinable2) => {
116
- Combinable2.string = {
117
- empty: "",
118
- combine: (b) => (a) => a + b
119
- };
120
- Combinable2.sum = {
121
- empty: 0,
122
- combine: (b) => (a) => a + b
123
- };
124
- Combinable2.product = {
125
- empty: 1,
126
- combine: (b) => (a) => a * b
127
- };
128
- Combinable2.all = {
129
- empty: true,
130
- combine: (b) => (a) => a && b
131
- };
132
- Combinable2.any = {
133
- empty: false,
134
- combine: (b) => (a) => a || b
135
- };
136
- Combinable2.array = () => ({
137
- empty: [],
138
- combine: (b) => (a) => [...a, ...b]
139
- });
131
+ Combinable2.string = { empty: "", combine: (b) => (a) => a + b };
132
+ Combinable2.sum = { empty: 0, combine: (b) => (a) => a + b };
133
+ Combinable2.product = { empty: 1, combine: (b) => (a) => a * b };
134
+ Combinable2.all = { empty: true, combine: (b) => (a) => a && b };
135
+ Combinable2.any = { empty: false, combine: (b) => (a) => a || b };
136
+ Combinable2.array = () => ({ empty: [], combine: (b) => (a) => [...a, ...b] });
140
137
  Combinable2.maybe = (inner) => ({
141
138
  empty: Maybe.none(),
142
139
  combine: (b) => (a) => Maybe.isNone(a) ? b : Maybe.isNone(b) ? a : Maybe.some(inner.combine(b.value)(a.value))
@@ -196,17 +193,11 @@ var Lazy;
196
193
  var Lens;
197
194
  ((Lens2) => {
198
195
  Lens2.make = (get2, set2) => ({ get: get2, set: set2 });
199
- Lens2.prop = () => (key) => (0, Lens2.make)(
200
- (s) => s[key],
201
- (a) => (s) => ({ ...s, [key]: a })
202
- );
196
+ Lens2.prop = () => (key) => (0, Lens2.make)((s) => s[key], (a) => (s) => ({ ...s, [key]: a }));
203
197
  Lens2.get = (lens) => (s) => lens.get(s);
204
198
  Lens2.set = (lens) => (a) => (s) => lens.set(a)(s);
205
199
  Lens2.modify = (lens) => (f) => (s) => lens.set(f(lens.get(s)))(s);
206
- Lens2.andThen = (inner) => (outer) => (0, Lens2.make)(
207
- (s) => inner.get(outer.get(s)),
208
- (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
209
- );
200
+ Lens2.andThen = (inner) => (outer) => (0, Lens2.make)((s) => inner.get(outer.get(s)), (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s));
210
201
  Lens2.andThenOptional = (inner) => (outer) => ({
211
202
  get: (s) => inner.get(outer.get(s)),
212
203
  set: (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
@@ -241,6 +232,31 @@ var Logged;
241
232
  Logged2.run = (data) => [data.value, data.log];
242
233
  })(Logged || (Logged = {}));
243
234
 
235
+ // src/Types/Brand.ts
236
+ var Brand;
237
+ ((Brand2) => {
238
+ Brand2.wrap = () => (value) => value;
239
+ Brand2.unwrap = (branded) => branded;
240
+ })(Brand || (Brand = {}));
241
+
242
+ // src/Types/Duration.ts
243
+ var Duration;
244
+ ((Duration2) => {
245
+ const wrap = Brand.wrap();
246
+ Duration2.milliseconds = (ms) => wrap(ms);
247
+ Duration2.seconds = (s) => wrap(s * 1e3);
248
+ Duration2.minutes = (m) => wrap(m * 60 * 1e3);
249
+ Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
250
+ Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
251
+ Duration2.toMilliseconds = (d) => Brand.unwrap(d);
252
+ Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
253
+ Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
254
+ Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
255
+ Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
256
+ Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
257
+ Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
258
+ })(Duration || (Duration = {}));
259
+
244
260
  // src/internal/Op.util.ts
245
261
  var _abortedNil = { kind: "OpNil", reason: "aborted" };
246
262
  var _droppedNil = { kind: "OpNil", reason: "dropped" };
@@ -249,11 +265,15 @@ var _evictedNil = { kind: "OpNil", reason: "evicted" };
249
265
  var _idle = { kind: "Idle" };
250
266
  var _pending = { kind: "Pending" };
251
267
  var ok = (value) => ({ kind: "OpOk", value });
252
- var err = (error) => ({ kind: "OpError", error });
253
- var cancellableWait = (ms, signal) => {
254
- if (ms <= 0) return Promise.resolve();
268
+ var err = (error) => ({ kind: "OpErr", error });
269
+ var getMs = (duration) => Duration.toMilliseconds(duration);
270
+ var cancellableWait = (duration, signal) => {
271
+ const rawMs = getMs(duration);
272
+ if (rawMs <= 0) {
273
+ return Promise.resolve();
274
+ }
255
275
  return new Promise((resolve) => {
256
- const id = setTimeout(resolve, ms);
276
+ const id = setTimeout(resolve, rawMs);
257
277
  signal.addEventListener("abort", () => {
258
278
  clearTimeout(id);
259
279
  resolve();
@@ -262,23 +282,41 @@ var cancellableWait = (ms, signal) => {
262
282
  };
263
283
  var runWithRetry = (op, input, signal, options, onRetrying) => {
264
284
  const { attempts, backoff, when: shouldRetry } = options;
265
- const getDelay = (n) => backoff === void 0 ? 0 : typeof backoff === "function" ? backoff(n) : backoff;
285
+ const getDelay = (n) => {
286
+ if (backoff === void 0) {
287
+ return void 0;
288
+ }
289
+ return typeof backoff === "function" ? backoff(n) : backoff;
290
+ };
266
291
  const attempt = async (left) => {
267
292
  const result = await Deferred.toPromise(op._factory(input, signal));
268
- if (result === null || signal.aborted) return null;
269
- if (result.kind === "Ok") return result;
270
- if (left <= 1) return result;
271
- if (shouldRetry !== void 0 && !shouldRetry(result.error)) return result;
293
+ if (result === null || signal.aborted) {
294
+ return null;
295
+ }
296
+ if (result.kind === "Ok") {
297
+ return result;
298
+ }
299
+ if (left <= 1) {
300
+ return result;
301
+ }
302
+ if (shouldRetry !== void 0 && !shouldRetry(result.error)) {
303
+ return result;
304
+ }
272
305
  const attemptNumber = attempts - left + 1;
273
- const ms = getDelay(attemptNumber);
306
+ const delayDuration = getDelay(attemptNumber);
307
+ const ms = delayDuration ? getMs(delayDuration) : 0;
274
308
  onRetrying({
275
309
  kind: "Retrying",
276
310
  attempt: attemptNumber,
277
311
  lastError: result.error,
278
312
  ...ms > 0 ? { nextRetryIn: ms } : {}
279
313
  });
280
- await cancellableWait(ms, signal);
281
- if (signal.aborted) return null;
314
+ if (delayDuration) {
315
+ await cancellableWait(delayDuration, signal);
316
+ }
317
+ if (signal.aborted) {
318
+ return null;
319
+ }
282
320
  return attempt(left - 1);
283
321
  };
284
322
  return attempt(attempts);
@@ -287,7 +325,9 @@ var execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying)
287
325
  const { signal } = controller;
288
326
  const toOutcome = (r) => r === null ? _abortedNil : r.kind === "Ok" ? ok(r.value) : err(r.error);
289
327
  const runPromise = retryOptions !== void 0 && onRetrying !== void 0 ? runWithRetry(op, input, signal, retryOptions, onRetrying).then(toOutcome) : Deferred.toPromise(op._factory(input, signal)).then(toOutcome);
290
- if (timeoutOptions === void 0) return Deferred.fromPromise(runPromise);
328
+ if (timeoutOptions === void 0) {
329
+ return Deferred.fromPromise(runPromise);
330
+ }
291
331
  let timerId;
292
332
  return Deferred.fromPromise(Promise.race([
293
333
  runPromise.then((outcome) => {
@@ -298,7 +338,7 @@ var execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying)
298
338
  timerId = setTimeout(() => {
299
339
  controller.abort();
300
340
  resolve(err(timeoutOptions.onTimeout()));
301
- }, timeoutOptions.ms);
341
+ }, getMs(timeoutOptions.duration));
302
342
  })
303
343
  ]));
304
344
  };
@@ -324,14 +364,20 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
324
364
  const controller = currentController;
325
365
  prev?.(_replacedNil);
326
366
  const startExecution = () => {
327
- if (currentController !== controller) return;
367
+ if (currentController !== controller) {
368
+ return;
369
+ }
328
370
  lastStartTime = Date.now();
329
371
  emit(_pending);
330
372
  const onRetrying = retryOptions ? (r) => {
331
- if (currentController === controller) emit(r);
373
+ if (currentController === controller) {
374
+ emit(r);
375
+ }
332
376
  } : void 0;
333
377
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
334
- if (currentController !== controller) return;
378
+ if (currentController !== controller) {
379
+ return;
380
+ }
335
381
  const r = currentResolve;
336
382
  currentResolve = void 0;
337
383
  currentController = void 0;
@@ -339,12 +385,14 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
339
385
  r?.(outcome);
340
386
  });
341
387
  };
342
- const gap = minInterval !== void 0 ? Math.max(0, minInterval - (Date.now() - lastStartTime)) : 0;
388
+ const gap = minInterval !== void 0 ? Math.max(0, getMs(minInterval) - (Date.now() - lastStartTime)) : 0;
343
389
  if (gap > 0) {
344
390
  waitController = new AbortController();
345
391
  const wc = waitController;
346
- cancellableWait(gap, wc.signal).then(() => {
347
- if (waitController === wc) waitController = void 0;
392
+ cancellableWait(Duration.milliseconds(gap), wc.signal).then(() => {
393
+ if (waitController === wc) {
394
+ waitController = void 0;
395
+ }
348
396
  startExecution();
349
397
  });
350
398
  } else {
@@ -359,7 +407,9 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
359
407
  currentController = void 0;
360
408
  const r = currentResolve;
361
409
  currentResolve = void 0;
362
- if (currentState.kind !== "Idle") emit(_abortedNil);
410
+ if (currentState.kind !== "Idle") {
411
+ emit(_abortedNil);
412
+ }
363
413
  r?.(_abortedNil);
364
414
  };
365
415
  return {
@@ -370,13 +420,15 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
370
420
  abort,
371
421
  subscribe: (cb) => {
372
422
  subscribers.add(cb);
373
- if (currentState.kind !== "Idle") cb(currentState);
423
+ if (currentState.kind !== "Idle") {
424
+ cb(currentState);
425
+ }
374
426
  return () => subscribers.delete(cb);
375
427
  },
376
428
  reset: () => emit(_idle),
377
429
  poll: (input, { interval }) => {
378
430
  void run(input);
379
- const id = setInterval(() => void run(input), interval);
431
+ const id = setInterval(() => void run(input), getMs(interval));
380
432
  return () => clearInterval(id);
381
433
  }
382
434
  };
@@ -402,19 +454,26 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
402
454
  const controller = currentController;
403
455
  emit(_pending);
404
456
  const onRetrying = retryOptions ? (r) => {
405
- if (currentController === controller) emit(r);
457
+ if (currentController === controller) {
458
+ emit(r);
459
+ }
406
460
  } : void 0;
407
461
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
408
- if (currentController !== controller) return;
462
+ if (currentController !== controller) {
463
+ return;
464
+ }
409
465
  const r = currentResolve;
410
466
  currentResolve = void 0;
411
467
  currentController = void 0;
412
468
  emit(outcome);
413
469
  r?.(outcome);
414
- if (cooldown !== void 0 && cooldown > 0) {
415
- cooldownTimer = setTimeout(() => {
416
- cooldownTimer = void 0;
417
- }, cooldown);
470
+ if (cooldown !== void 0) {
471
+ const rawCooldown = getMs(cooldown);
472
+ if (rawCooldown > 0) {
473
+ cooldownTimer = setTimeout(() => {
474
+ cooldownTimer = void 0;
475
+ }, rawCooldown);
476
+ }
418
477
  }
419
478
  });
420
479
  })
@@ -429,7 +488,9 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
429
488
  currentController = void 0;
430
489
  const r = currentResolve;
431
490
  currentResolve = void 0;
432
- if (currentState.kind !== "Idle") emit(_abortedNil);
491
+ if (currentState.kind !== "Idle") {
492
+ emit(_abortedNil);
493
+ }
433
494
  r?.(_abortedNil);
434
495
  };
435
496
  return {
@@ -440,13 +501,15 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
440
501
  abort,
441
502
  subscribe: (cb) => {
442
503
  subscribers.add(cb);
443
- if (currentState.kind !== "Idle") cb(currentState);
504
+ if (currentState.kind !== "Idle") {
505
+ cb(currentState);
506
+ }
444
507
  return () => subscribers.delete(cb);
445
508
  },
446
509
  reset: () => emit(_idle),
447
510
  poll: (input, { interval }) => {
448
511
  void run(input);
449
- const id = setInterval(() => void run(input), interval);
512
+ const id = setInterval(() => void run(input), getMs(interval));
450
513
  return () => clearInterval(id);
451
514
  }
452
515
  };
@@ -471,12 +534,16 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
471
534
  inflightResolvers.push(resolve);
472
535
  emit(_pending);
473
536
  const onRetrying = retryOptions ? (r) => {
474
- if (generation === myGeneration && inflightControllers.has(controller)) emit(r);
537
+ if (generation === myGeneration && inflightControllers.has(controller)) {
538
+ emit(r);
539
+ }
475
540
  } : void 0;
476
541
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
477
542
  inflightControllers.delete(controller);
478
543
  const idx = inflightResolvers.indexOf(resolve);
479
- if (idx !== -1) inflightResolvers.splice(idx, 1);
544
+ if (idx !== -1) {
545
+ inflightResolvers.splice(idx, 1);
546
+ }
480
547
  if (generation !== myGeneration) {
481
548
  resolve(_abortedNil);
482
549
  return;
@@ -533,7 +600,9 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
533
600
  const toResolve = inflightResolvers.splice(0);
534
601
  const queuedResolvers = queue.splice(0).map((item) => item.resolve);
535
602
  inFlight = 0;
536
- if (currentState.kind !== "Idle") emit(_abortedNil);
603
+ if (currentState.kind !== "Idle") {
604
+ emit(_abortedNil);
605
+ }
537
606
  toResolve.forEach((r) => r(_abortedNil));
538
607
  queuedResolvers.forEach((r) => r(_abortedNil));
539
608
  };
@@ -545,13 +614,15 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
545
614
  abort,
546
615
  subscribe: (cb) => {
547
616
  subscribers.add(cb);
548
- if (currentState.kind !== "Idle") cb(currentState);
617
+ if (currentState.kind !== "Idle") {
618
+ cb(currentState);
619
+ }
549
620
  return () => subscribers.delete(cb);
550
621
  },
551
622
  reset: () => emit(_idle),
552
623
  poll: (input, { interval }) => {
553
624
  void run(input);
554
- const id = setInterval(() => void run(input), interval);
625
+ const id = setInterval(() => void run(input), getMs(interval));
555
626
  return () => clearInterval(id);
556
627
  }
557
628
  };
@@ -573,10 +644,14 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
573
644
  const controller = currentController;
574
645
  emit(_pending);
575
646
  const onRetrying = retryOptions ? (r) => {
576
- if (currentController === controller) emit(r);
647
+ if (currentController === controller) {
648
+ emit(r);
649
+ }
577
650
  } : void 0;
578
651
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
579
- if (currentController !== controller) return;
652
+ if (currentController !== controller) {
653
+ return;
654
+ }
580
655
  const r = currentResolve;
581
656
  currentResolve = void 0;
582
657
  currentController = void 0;
@@ -609,7 +684,9 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
609
684
  const cr = currentResolve;
610
685
  currentResolve = void 0;
611
686
  const bufferedResolvers = buffer.splice(0).map((item) => item.resolve);
612
- if (currentState.kind !== "Idle") emit(_abortedNil);
687
+ if (currentState.kind !== "Idle") {
688
+ emit(_abortedNil);
689
+ }
613
690
  cr?.(_abortedNil);
614
691
  bufferedResolvers.forEach((r) => r(_abortedNil));
615
692
  };
@@ -621,18 +698,20 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
621
698
  abort,
622
699
  subscribe: (cb) => {
623
700
  subscribers.add(cb);
624
- if (currentState.kind !== "Idle") cb(currentState);
701
+ if (currentState.kind !== "Idle") {
702
+ cb(currentState);
703
+ }
625
704
  return () => subscribers.delete(cb);
626
705
  },
627
706
  reset: () => emit(_idle),
628
707
  poll: (input, { interval }) => {
629
708
  void run(input);
630
- const id = setInterval(() => void run(input), interval);
709
+ const id = setInterval(() => void run(input), getMs(interval));
631
710
  return () => clearInterval(id);
632
711
  }
633
712
  };
634
713
  };
635
- var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) => {
714
+ var makeDebounced = (op, duration, leading, maxWait, retryOptions, timeoutOptions) => {
636
715
  let currentState = _idle;
637
716
  let currentController;
638
717
  let currentResolve;
@@ -653,10 +732,14 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
653
732
  leadingResolve = resolve;
654
733
  emit(_pending);
655
734
  const onRetrying = retryOptions ? (r) => {
656
- if (leadingController === controller) emit(r);
735
+ if (leadingController === controller) {
736
+ emit(r);
737
+ }
657
738
  } : void 0;
658
739
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
659
- if (leadingController !== controller) return;
740
+ if (leadingController !== controller) {
741
+ return;
742
+ }
660
743
  const r = leadingResolve;
661
744
  leadingResolve = void 0;
662
745
  leadingController = void 0;
@@ -669,7 +752,9 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
669
752
  firstCallAt = 0;
670
753
  const capturedResolve = pendingResolve;
671
754
  pendingResolve = void 0;
672
- if (capturedResolve === void 0) return;
755
+ if (capturedResolve === void 0) {
756
+ return;
757
+ }
673
758
  currentResolve = capturedResolve;
674
759
  const toRun = pendingInput;
675
760
  pendingInput = void 0;
@@ -677,10 +762,14 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
677
762
  const controller = currentController;
678
763
  emit(_pending);
679
764
  const onRetrying = retryOptions ? (r) => {
680
- if (currentController === controller) emit(r);
765
+ if (currentController === controller) {
766
+ emit(r);
767
+ }
681
768
  } : void 0;
682
769
  execute(op, toRun, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
683
- if (currentController !== controller) return;
770
+ if (currentController !== controller) {
771
+ return;
772
+ }
684
773
  const r = currentResolve;
685
774
  currentResolve = void 0;
686
775
  currentController = void 0;
@@ -689,11 +778,13 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
689
778
  });
690
779
  };
691
780
  const scheduleTrailing = () => {
692
- if (timerId !== void 0) clearTimeout(timerId);
693
- let delay = ms;
781
+ if (timerId !== void 0) {
782
+ clearTimeout(timerId);
783
+ }
784
+ let delay = getMs(duration);
694
785
  if (maxWait !== void 0 && firstCallAt > 0) {
695
- const maxDelay = firstCallAt + maxWait - Date.now();
696
- delay = Math.min(ms, Math.max(0, maxDelay));
786
+ const maxDelay = firstCallAt + getMs(maxWait) - Date.now();
787
+ delay = Math.min(getMs(duration), Math.max(0, maxDelay));
697
788
  }
698
789
  timerId = setTimeout(fireTrailing, delay);
699
790
  };
@@ -736,7 +827,9 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
736
827
  leadingResolve = void 0;
737
828
  leadingController?.abort();
738
829
  leadingController = void 0;
739
- if (currentState.kind !== "Idle") emit(_abortedNil);
830
+ if (currentState.kind !== "Idle") {
831
+ emit(_abortedNil);
832
+ }
740
833
  pr?.(_abortedNil);
741
834
  cr?.(_abortedNil);
742
835
  lr?.(_abortedNil);
@@ -749,18 +842,20 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
749
842
  abort,
750
843
  subscribe: (cb) => {
751
844
  subscribers.add(cb);
752
- if (currentState.kind !== "Idle") cb(currentState);
845
+ if (currentState.kind !== "Idle") {
846
+ cb(currentState);
847
+ }
753
848
  return () => subscribers.delete(cb);
754
849
  },
755
850
  reset: () => emit(_idle),
756
851
  poll: (input, { interval }) => {
757
852
  void run(input);
758
- const id = setInterval(() => void run(input), interval);
853
+ const id = setInterval(() => void run(input), getMs(interval));
759
854
  return () => clearInterval(id);
760
855
  }
761
856
  };
762
857
  };
763
- var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
858
+ var makeThrottled = (op, duration, trailing, retryOptions, timeoutOptions) => {
764
859
  let currentState = _idle;
765
860
  let currentController;
766
861
  let currentResolve;
@@ -778,10 +873,14 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
778
873
  const controller = currentController;
779
874
  emit(_pending);
780
875
  const onRetrying = retryOptions ? (r) => {
781
- if (currentController === controller) emit(r);
876
+ if (currentController === controller) {
877
+ emit(r);
878
+ }
782
879
  } : void 0;
783
880
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
784
- if (currentController !== controller) return;
881
+ if (currentController !== controller) {
882
+ return;
883
+ }
785
884
  const r = currentResolve;
786
885
  currentResolve = void 0;
787
886
  currentController = void 0;
@@ -800,7 +899,7 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
800
899
  fireOp(input, resolve);
801
900
  startCooldown();
802
901
  }
803
- }, ms);
902
+ }, getMs(duration));
804
903
  };
805
904
  const run = (input) => {
806
905
  if (cooldownTimer !== void 0) {
@@ -835,7 +934,9 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
835
934
  const pr = pendingResolve;
836
935
  pendingResolve = void 0;
837
936
  pendingInput = void 0;
838
- if (currentState.kind !== "Idle") emit(_abortedNil);
937
+ if (currentState.kind !== "Idle") {
938
+ emit(_abortedNil);
939
+ }
839
940
  cr?.(_abortedNil);
840
941
  pr?.(_abortedNil);
841
942
  };
@@ -847,13 +948,15 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
847
948
  abort,
848
949
  subscribe: (cb) => {
849
950
  subscribers.add(cb);
850
- if (currentState.kind !== "Idle") cb(currentState);
951
+ if (currentState.kind !== "Idle") {
952
+ cb(currentState);
953
+ }
851
954
  return () => subscribers.delete(cb);
852
955
  },
853
956
  reset: () => emit(_idle),
854
957
  poll: (input, { interval }) => {
855
958
  void run(input);
856
- const id = setInterval(() => void run(input), interval);
959
+ const id = setInterval(() => void run(input), getMs(interval));
857
960
  return () => clearInterval(id);
858
961
  }
859
962
  };
@@ -877,12 +980,16 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
877
980
  inflightResolvers.push(resolve);
878
981
  emit(_pending);
879
982
  const onRetrying = retryOptions ? (r) => {
880
- if (generation === myGeneration && controllers.has(controller)) emit(r);
983
+ if (generation === myGeneration && controllers.has(controller)) {
984
+ emit(r);
985
+ }
881
986
  } : void 0;
882
987
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
883
988
  controllers.delete(controller);
884
989
  const idx = inflightResolvers.indexOf(resolve);
885
- if (idx !== -1) inflightResolvers.splice(idx, 1);
990
+ if (idx !== -1) {
991
+ inflightResolvers.splice(idx, 1);
992
+ }
886
993
  if (generation !== myGeneration) {
887
994
  resolve(_abortedNil);
888
995
  return;
@@ -922,7 +1029,9 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
922
1029
  const toResolve = inflightResolvers.splice(0);
923
1030
  const queuedResolvers = overflowQueue.splice(0).map((item) => item.resolve);
924
1031
  inflight = 0;
925
- if (currentState.kind !== "Idle") emit(_abortedNil);
1032
+ if (currentState.kind !== "Idle") {
1033
+ emit(_abortedNil);
1034
+ }
926
1035
  toResolve.forEach((r) => r(_abortedNil));
927
1036
  queuedResolvers.forEach((r) => r(_abortedNil));
928
1037
  };
@@ -934,13 +1043,15 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
934
1043
  abort,
935
1044
  subscribe: (cb) => {
936
1045
  subscribers.add(cb);
937
- if (currentState.kind !== "Idle") cb(currentState);
1046
+ if (currentState.kind !== "Idle") {
1047
+ cb(currentState);
1048
+ }
938
1049
  return () => subscribers.delete(cb);
939
1050
  },
940
1051
  reset: () => emit(_idle),
941
1052
  poll: (input, { interval }) => {
942
1053
  void run(input);
943
- const id = setInterval(() => void run(input), interval);
1054
+ const id = setInterval(() => void run(input), getMs(interval));
944
1055
  return () => clearInterval(id);
945
1056
  }
946
1057
  };
@@ -971,7 +1082,7 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
971
1082
  slots.set(k, { controller, resolve });
972
1083
  stateMap.set(k, _pending);
973
1084
  emitSnapshot();
974
- execute(op, input, controller, void 0, timeoutOptions, void 0).then((outcome) => {
1085
+ execute(op, input, controller, void 0, timeoutOptions).then((outcome) => {
975
1086
  const slot = slots.get(k);
976
1087
  if (!slot || slot.controller !== controller) {
977
1088
  resolve(_abortedNil);
@@ -1004,7 +1115,9 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1004
1115
  stateMap.set(k, _abortedNil);
1005
1116
  }
1006
1117
  slots.clear();
1007
- if (toResolve.length > 0) emitSnapshot();
1118
+ if (toResolve.length > 0) {
1119
+ emitSnapshot();
1120
+ }
1008
1121
  toResolve.forEach((r) => r(_abortedNil));
1009
1122
  }
1010
1123
  };
@@ -1016,7 +1129,9 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1016
1129
  abort,
1017
1130
  subscribe: (cb) => {
1018
1131
  subscribers.add(cb);
1019
- if (stateMap.size > 0) cb(new Map(stateMap));
1132
+ if (stateMap.size > 0) {
1133
+ cb(new Map(stateMap));
1134
+ }
1020
1135
  return () => subscribers.delete(cb);
1021
1136
  },
1022
1137
  reset: () => {
@@ -1025,7 +1140,7 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1025
1140
  },
1026
1141
  poll: (input, { interval }) => {
1027
1142
  void run(input);
1028
- const id = setInterval(() => void run(input), interval);
1143
+ const id = setInterval(() => void run(input), getMs(interval));
1029
1144
  return () => clearInterval(id);
1030
1145
  }
1031
1146
  };
@@ -1050,10 +1165,14 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
1050
1165
  const controller = currentController;
1051
1166
  emit(_pending);
1052
1167
  const onRetrying = retryOptions ? (r) => {
1053
- if (currentController === controller) emit(r);
1168
+ if (currentController === controller) {
1169
+ emit(r);
1170
+ }
1054
1171
  } : void 0;
1055
1172
  execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
1056
- if (currentController !== controller) return;
1173
+ if (currentController !== controller) {
1174
+ return;
1175
+ }
1057
1176
  const r = currentResolve;
1058
1177
  currentResolve = void 0;
1059
1178
  currentController = void 0;
@@ -1068,7 +1187,9 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
1068
1187
  currentController = void 0;
1069
1188
  const r = currentResolve;
1070
1189
  currentResolve = void 0;
1071
- if (currentState.kind !== "Idle") emit(_abortedNil);
1190
+ if (currentState.kind !== "Idle") {
1191
+ emit(_abortedNil);
1192
+ }
1072
1193
  r?.(_abortedNil);
1073
1194
  };
1074
1195
  return {
@@ -1079,13 +1200,15 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
1079
1200
  abort,
1080
1201
  subscribe: (cb) => {
1081
1202
  subscribers.add(cb);
1082
- if (currentState.kind !== "Idle") cb(currentState);
1203
+ if (currentState.kind !== "Idle") {
1204
+ cb(currentState);
1205
+ }
1083
1206
  return () => subscribers.delete(cb);
1084
1207
  },
1085
1208
  reset: () => emit(_idle),
1086
1209
  poll: (input, { interval }) => {
1087
1210
  void run(input);
1088
- const id = setInterval(() => void run(input), interval);
1211
+ const id = setInterval(() => void run(input), getMs(interval));
1089
1212
  return () => clearInterval(id);
1090
1213
  }
1091
1214
  };
@@ -1097,62 +1220,80 @@ var Op;
1097
1220
  Op2.nil = (reason) => ({ kind: "OpNil", reason });
1098
1221
  Op2.create = (factory, onError) => ({
1099
1222
  _factory: (input, signal) => Deferred.fromPromise(
1100
- factory(signal)(input).then((value) => Result.ok(value)).catch((e) => signal.aborted ? null : Result.error(onError(e)))
1223
+ factory(signal)(input).then((value) => Result.ok(value)).catch(
1224
+ (error) => signal.aborted ? null : Result.err(onError(error))
1225
+ )
1101
1226
  )
1102
1227
  });
1103
- Op2.lift = (f) => (0, Op2.create)(
1104
- (signal) => (input) => f(input, signal),
1105
- (e) => e
1106
- );
1228
+ Op2.lift = (f) => (0, Op2.create)((signal) => (input) => f(input, signal), (e) => e);
1107
1229
  Op2.ok = (value) => ({ kind: "OpOk", value });
1108
- Op2.error = (error2) => ({ kind: "OpError", error: error2 });
1230
+ Op2.err = (error) => ({ kind: "OpErr", error });
1109
1231
  Op2.isIdle = (state) => state.kind === "Idle";
1110
1232
  Op2.isPending = (state) => state.kind === "Pending";
1111
1233
  Op2.isQueued = (state) => state.kind === "Queued";
1112
1234
  Op2.isRetrying = (state) => state.kind === "Retrying";
1113
1235
  Op2.isOk = (state) => state.kind === "OpOk";
1114
- Op2.isError = (state) => state.kind === "OpError";
1236
+ Op2.isErr = (state) => state.kind === "OpErr";
1115
1237
  Op2.isNil = (state) => state.kind === "OpNil";
1116
1238
  Op2.match = (cases) => (outcome) => {
1117
- if (outcome.kind === "OpOk") return cases.ok(outcome.value);
1118
- if (outcome.kind === "OpError") return cases.error(outcome.error);
1239
+ if (outcome.kind === "OpOk") {
1240
+ return cases.ok(outcome.value);
1241
+ }
1242
+ if (outcome.kind === "OpErr") {
1243
+ return cases.err(outcome.error);
1244
+ }
1119
1245
  return cases.nil();
1120
1246
  };
1121
- Op2.fold = (onError, onOk, onNil) => (outcome) => {
1122
- if (outcome.kind === "OpOk") return onOk(outcome.value);
1123
- if (outcome.kind === "OpError") return onError(outcome.error);
1247
+ Op2.fold = (onErr, onOk, onNil) => (outcome) => {
1248
+ if (outcome.kind === "OpOk") {
1249
+ return onOk(outcome.value);
1250
+ }
1251
+ if (outcome.kind === "OpErr") {
1252
+ return onErr(outcome.error);
1253
+ }
1124
1254
  return onNil();
1125
1255
  };
1126
1256
  Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "OpOk" ? outcome.value : defaultValue();
1127
1257
  Op2.map = (f) => (outcome) => outcome.kind === "OpOk" ? (0, Op2.ok)(f(outcome.value)) : outcome;
1128
- Op2.mapError = (f) => (outcome) => outcome.kind === "OpError" ? (0, Op2.error)(f(outcome.error)) : outcome;
1258
+ Op2.mapError = (f) => (outcome) => outcome.kind === "OpErr" ? (0, Op2.err)(f(outcome.error)) : outcome;
1129
1259
  Op2.chain = (f) => (outcome) => outcome.kind === "OpOk" ? f(outcome.value) : outcome;
1130
1260
  Op2.tap = (f) => (outcome) => {
1131
- if (outcome.kind === "OpOk") f(outcome.value);
1261
+ if (outcome.kind === "OpOk") {
1262
+ f(outcome.value);
1263
+ }
1132
1264
  return outcome;
1133
1265
  };
1134
- Op2.recover = (f) => (outcome) => outcome.kind === "OpError" ? f(outcome.error) : outcome;
1266
+ Op2.recover = (f) => (outcome) => outcome.kind === "OpErr" ? f(outcome.error) : outcome;
1135
1267
  Op2.toResult = (onNil) => (outcome) => {
1136
- if (outcome.kind === "OpOk") return Result.ok(outcome.value);
1137
- if (outcome.kind === "OpError") return Result.error(outcome.error);
1138
- return Result.error(onNil());
1268
+ if (outcome.kind === "OpOk") {
1269
+ return Result.ok(outcome.value);
1270
+ }
1271
+ if (outcome.kind === "OpErr") {
1272
+ return Result.err(outcome.error);
1273
+ }
1274
+ return Result.err(onNil());
1139
1275
  };
1140
1276
  Op2.toMaybe = (outcome) => outcome.kind === "OpOk" ? Maybe.some(outcome.value) : Maybe.none();
1141
1277
  Op2.all = (invocations) => Deferred.fromPromise(Promise.all(invocations.map(Deferred.toPromise)));
1142
1278
  Op2.race = (invocations) => Deferred.fromPromise(Promise.race(invocations.map(Deferred.toPromise)));
1143
1279
  Op2.wire = (source, f) => source.subscribe((state) => {
1144
- if ((0, Op2.isOk)(state)) f(state.value);
1280
+ if ((0, Op2.isOk)(state)) {
1281
+ f(state.value);
1282
+ }
1145
1283
  });
1146
1284
  function interpret(op, options) {
1147
1285
  const { strategy, retry: retryOptions, timeout: timeoutOptions } = options;
1148
1286
  switch (strategy) {
1149
- case "once":
1287
+ case "once": {
1150
1288
  return makeOnce(op, retryOptions, timeoutOptions);
1151
- case "restartable":
1289
+ }
1290
+ case "restartable": {
1152
1291
  return makeRestartable(op, options.minInterval, retryOptions, timeoutOptions);
1153
- case "exclusive":
1292
+ }
1293
+ case "exclusive": {
1154
1294
  return makeExclusive(op, options.cooldown, retryOptions, timeoutOptions);
1155
- case "queue":
1295
+ }
1296
+ case "queue": {
1156
1297
  return makeQueue(
1157
1298
  op,
1158
1299
  options.maxSize,
@@ -1162,13 +1303,24 @@ var Op;
1162
1303
  retryOptions,
1163
1304
  timeoutOptions
1164
1305
  );
1165
- case "buffered":
1306
+ }
1307
+ case "buffered": {
1166
1308
  return makeBuffered(op, options.size, retryOptions, timeoutOptions);
1167
- case "debounced":
1168
- return makeDebounced(op, options.ms ?? 0, options.leading ?? false, options.maxWait, retryOptions, timeoutOptions);
1169
- case "throttled":
1170
- return makeThrottled(op, options.ms ?? 0, options.trailing ?? false, retryOptions, timeoutOptions);
1171
- case "concurrent":
1309
+ }
1310
+ case "debounced": {
1311
+ return makeDebounced(
1312
+ op,
1313
+ options.duration,
1314
+ options.leading ?? false,
1315
+ options.maxWait,
1316
+ retryOptions,
1317
+ timeoutOptions
1318
+ );
1319
+ }
1320
+ case "throttled": {
1321
+ return makeThrottled(op, options.duration, options.trailing ?? false, retryOptions, timeoutOptions);
1322
+ }
1323
+ case "concurrent": {
1172
1324
  return makeConcurrent(
1173
1325
  op,
1174
1326
  options.n ?? 1,
@@ -1176,8 +1328,10 @@ var Op;
1176
1328
  retryOptions,
1177
1329
  timeoutOptions
1178
1330
  );
1179
- case "keyed":
1331
+ }
1332
+ case "keyed": {
1180
1333
  return makeKeyed(op, options.key ?? ((i) => i), options.perKey ?? "exclusive", timeoutOptions);
1334
+ }
1181
1335
  }
1182
1336
  }
1183
1337
  Op2.interpret = interpret;
@@ -1187,22 +1341,18 @@ var Op;
1187
1341
  var Optional;
1188
1342
  ((Optional2) => {
1189
1343
  Optional2.make = (get2, set2) => ({ get: get2, set: set2 });
1190
- Optional2.prop = () => (key) => (0, Optional2.make)(
1191
- (s) => {
1192
- const val = s[key];
1193
- return val !== null && val !== void 0 ? Maybe.some(val) : Maybe.none();
1194
- },
1195
- (a) => (s) => ({ ...s, [key]: a })
1196
- );
1197
- Optional2.index = (i) => (0, Optional2.make)(
1198
- (arr) => i >= 0 && i < arr.length ? Maybe.some(arr[i]) : Maybe.none(),
1199
- (a) => (arr) => {
1200
- if (i < 0 || i >= arr.length) return arr;
1201
- const copy = [...arr];
1202
- copy[i] = a;
1203
- return copy;
1344
+ Optional2.prop = () => (key) => (0, Optional2.make)((s) => {
1345
+ const val = s[key];
1346
+ return val !== null && val !== void 0 ? Maybe.some(val) : Maybe.none();
1347
+ }, (a) => (s) => ({ ...s, [key]: a }));
1348
+ Optional2.index = (i) => (0, Optional2.make)((arr) => i >= 0 && i < arr.length ? Maybe.some(arr[i]) : Maybe.none(), (a) => (arr) => {
1349
+ if (i < 0 || i >= arr.length) {
1350
+ return arr;
1204
1351
  }
1205
- );
1352
+ const copy = [...arr];
1353
+ copy[i] = a;
1354
+ return copy;
1355
+ });
1206
1356
  Optional2.get = (opt) => (s) => opt.get(s);
1207
1357
  Optional2.set = (opt) => (a) => (s) => opt.set(a)(s);
1208
1358
  Optional2.modify = (opt) => (f) => (s) => {
@@ -1221,26 +1371,20 @@ var Optional;
1221
1371
  const val = opt.get(s);
1222
1372
  return val.kind === "Some" ? cases.some(val.value) : cases.none();
1223
1373
  };
1224
- Optional2.andThen = (inner) => (outer) => (0, Optional2.make)(
1225
- (s) => {
1226
- const mid = outer.get(s);
1227
- return mid.kind === "None" ? Maybe.none() : inner.get(mid.value);
1228
- },
1229
- (b) => (s) => {
1230
- const mid = outer.get(s);
1231
- return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
1232
- }
1233
- );
1234
- Optional2.andThenLens = (inner) => (outer) => (0, Optional2.make)(
1235
- (s) => {
1236
- const mid = outer.get(s);
1237
- return mid.kind === "None" ? Maybe.none() : Maybe.some(inner.get(mid.value));
1238
- },
1239
- (b) => (s) => {
1240
- const mid = outer.get(s);
1241
- return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
1242
- }
1243
- );
1374
+ Optional2.andThen = (inner) => (outer) => (0, Optional2.make)((s) => {
1375
+ const mid = outer.get(s);
1376
+ return mid.kind === "None" ? Maybe.none() : inner.get(mid.value);
1377
+ }, (b) => (s) => {
1378
+ const mid = outer.get(s);
1379
+ return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
1380
+ });
1381
+ Optional2.andThenLens = (inner) => (outer) => (0, Optional2.make)((s) => {
1382
+ const mid = outer.get(s);
1383
+ return mid.kind === "None" ? Maybe.none() : Maybe.some(inner.get(mid.value));
1384
+ }, (b) => (s) => {
1385
+ const mid = outer.get(s);
1386
+ return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
1387
+ });
1244
1388
  })(Optional || (Optional = {}));
1245
1389
 
1246
1390
  // src/Core/Ordering.ts
@@ -1295,7 +1439,7 @@ var Refinement;
1295
1439
  Refinement2.and = (second) => (first) => (a) => first(a) && second(a);
1296
1440
  Refinement2.or = (second) => (first) => (a) => first(a) || second(a);
1297
1441
  Refinement2.toFilter = (r) => (a) => r(a) ? Maybe.some(a) : Maybe.none();
1298
- Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.error(onFail(a));
1442
+ Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.err(onFail(a));
1299
1443
  })(Refinement || (Refinement = {}));
1300
1444
 
1301
1445
  // src/Core/RemoteData.ts
@@ -1305,14 +1449,8 @@ var RemoteData;
1305
1449
  ((RemoteData2) => {
1306
1450
  RemoteData2.notAsked = () => _notAsked;
1307
1451
  RemoteData2.loading = () => _loading;
1308
- RemoteData2.failure = (error) => ({
1309
- kind: "Failure",
1310
- error
1311
- });
1312
- RemoteData2.success = (value) => ({
1313
- kind: "Success",
1314
- value
1315
- });
1452
+ RemoteData2.failure = (error) => ({ kind: "Failure", error });
1453
+ RemoteData2.success = (value) => ({ kind: "Success", value });
1316
1454
  RemoteData2.isNotAsked = (data) => data.kind === "NotAsked";
1317
1455
  RemoteData2.isLoading = (data) => data.kind === "Loading";
1318
1456
  RemoteData2.isFailure = (data) => data.kind === "Failure";
@@ -1324,47 +1462,65 @@ var RemoteData;
1324
1462
  if ((0, RemoteData2.isSuccess)(data) && (0, RemoteData2.isSuccess)(arg)) {
1325
1463
  return (0, RemoteData2.success)(data.value(arg.value));
1326
1464
  }
1327
- if ((0, RemoteData2.isFailure)(data)) return data;
1328
- if ((0, RemoteData2.isFailure)(arg)) return arg;
1329
- if ((0, RemoteData2.isLoading)(data) || (0, RemoteData2.isLoading)(arg)) return (0, RemoteData2.loading)();
1465
+ if ((0, RemoteData2.isFailure)(data)) {
1466
+ return data;
1467
+ }
1468
+ if ((0, RemoteData2.isFailure)(arg)) {
1469
+ return arg;
1470
+ }
1471
+ if ((0, RemoteData2.isLoading)(data) || (0, RemoteData2.isLoading)(arg)) {
1472
+ return (0, RemoteData2.loading)();
1473
+ }
1330
1474
  return (0, RemoteData2.notAsked)();
1331
1475
  };
1332
1476
  RemoteData2.fold = (onNotAsked, onLoading, onFailure, onSuccess) => (data) => {
1333
1477
  switch (data.kind) {
1334
- case "NotAsked":
1478
+ case "NotAsked": {
1335
1479
  return onNotAsked();
1336
- case "Loading":
1480
+ }
1481
+ case "Loading": {
1337
1482
  return onLoading();
1338
- case "Failure":
1483
+ }
1484
+ case "Failure": {
1339
1485
  return onFailure(data.error);
1340
- case "Success":
1486
+ }
1487
+ case "Success": {
1341
1488
  return onSuccess(data.value);
1489
+ }
1342
1490
  }
1343
1491
  };
1344
1492
  RemoteData2.match = (cases) => (data) => {
1345
1493
  switch (data.kind) {
1346
- case "NotAsked":
1494
+ case "NotAsked": {
1347
1495
  return cases.notAsked();
1348
- case "Loading":
1496
+ }
1497
+ case "Loading": {
1349
1498
  return cases.loading();
1350
- case "Failure":
1499
+ }
1500
+ case "Failure": {
1351
1501
  return cases.failure(data.error);
1352
- case "Success":
1502
+ }
1503
+ case "Success": {
1353
1504
  return cases.success(data.value);
1505
+ }
1354
1506
  }
1355
1507
  };
1356
1508
  RemoteData2.getOrElse = (defaultValue) => (data) => (0, RemoteData2.isSuccess)(data) ? data.value : defaultValue();
1357
1509
  RemoteData2.tap = (f) => (data) => {
1358
- if ((0, RemoteData2.isSuccess)(data)) f(data.value);
1510
+ if ((0, RemoteData2.isSuccess)(data)) {
1511
+ f(data.value);
1512
+ }
1359
1513
  return data;
1360
1514
  };
1361
1515
  RemoteData2.tapError = (f) => (data) => {
1362
- if ((0, RemoteData2.isFailure)(data)) f(data.error);
1516
+ if ((0, RemoteData2.isFailure)(data)) {
1517
+ f(data.error);
1518
+ }
1363
1519
  return data;
1364
1520
  };
1365
1521
  RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
1366
1522
  RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
1367
- RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.error((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
1523
+ RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
1368
1524
  RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
1369
1525
  RemoteData2.fromMaybe = (onNone) => (data) => Maybe.isSome(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(onNone());
1370
1526
  RemoteData2.filter = (pred, onFalse) => (data) => (0, RemoteData2.isSuccess)(data) ? pred(data.value) ? data : (0, RemoteData2.failure)(onFalse(data.value)) : data;
@@ -1372,6 +1528,7 @@ var RemoteData;
1372
1528
 
1373
1529
  // src/Core/Task.ts
1374
1530
  var toPromise = (task, signal) => Deferred.toPromise(task(signal));
1531
+ var getMs2 = (duration) => Duration.toMilliseconds(duration);
1375
1532
  var Task;
1376
1533
  ((Task2) => {
1377
1534
  Task2.resolve = (value) => () => Deferred.fromPromise(Promise.resolve(value));
@@ -1379,12 +1536,7 @@ var Task;
1379
1536
  Task2.fromSync = (f) => () => Deferred.fromPromise(Promise.resolve(f()));
1380
1537
  Task2.map = (f) => (data) => (0, Task2.from)((signal) => toPromise(data, signal).then(f));
1381
1538
  Task2.chain = (f) => (data) => (0, Task2.from)((signal) => toPromise(data, signal).then((a) => toPromise(f(a), signal)));
1382
- Task2.ap = (arg) => (data) => (0, Task2.from)(
1383
- (signal) => Promise.all([
1384
- toPromise(data, signal),
1385
- toPromise(arg, signal)
1386
- ]).then(([f, a]) => f(a))
1387
- );
1539
+ Task2.ap = (arg) => (data) => (0, Task2.from)((signal) => Promise.all([toPromise(data, signal), toPromise(arg, signal)]).then(([f, a]) => f(a)));
1388
1540
  Task2.tap = (f) => (data) => (0, Task2.from)(
1389
1541
  (signal) => toPromise(data, signal).then((a) => {
1390
1542
  f(a);
@@ -1394,35 +1546,39 @@ var Task;
1394
1546
  Task2.all = (tasks) => (0, Task2.from)(
1395
1547
  (signal) => Promise.all(tasks.map((t) => toPromise(t, signal)))
1396
1548
  );
1397
- Task2.delay = (ms) => (data) => (0, Task2.from)(
1398
- (signal) => new Promise((resolve2) => {
1399
- let timerId = void 0;
1549
+ Task2.delay = (duration) => (data) => (0, Task2.from)(
1550
+ (signal) => new Promise((res) => {
1551
+ let timerId;
1400
1552
  const onAbort = () => {
1401
1553
  if (timerId !== void 0) {
1402
1554
  clearTimeout(timerId);
1403
1555
  }
1404
- resolve2(toPromise(data, signal));
1556
+ res(toPromise(data, signal));
1405
1557
  };
1406
1558
  if (signal) {
1407
1559
  if (signal.aborted) {
1408
- return resolve2(toPromise(data, signal));
1560
+ return res(toPromise(data, signal));
1409
1561
  }
1410
1562
  signal.addEventListener("abort", onAbort, { once: true });
1411
1563
  }
1412
1564
  timerId = setTimeout(() => {
1413
1565
  signal?.removeEventListener("abort", onAbort);
1414
- resolve2(toPromise(data, signal));
1415
- }, ms);
1566
+ res(toPromise(data, signal));
1567
+ }, getMs2(duration));
1416
1568
  })
1417
1569
  );
1418
1570
  Task2.repeat = (options) => (task) => (0, Task2.from)((signal) => {
1419
- const { times, delay: ms } = options;
1420
- if (times <= 0) return Promise.resolve([]);
1571
+ const { times, delay: delayDuration } = options;
1572
+ if (times <= 0) {
1573
+ return Promise.resolve([]);
1574
+ }
1421
1575
  const results = [];
1422
1576
  const wait = () => {
1423
- if (signal?.aborted) return Promise.resolve();
1577
+ if (signal?.aborted) {
1578
+ return Promise.resolve();
1579
+ }
1424
1580
  return new Promise((r) => {
1425
- let timerId = void 0;
1581
+ let timerId;
1426
1582
  const onAbort = () => {
1427
1583
  if (timerId !== void 0) {
1428
1584
  clearTimeout(timerId);
@@ -1435,7 +1591,7 @@ var Task;
1435
1591
  timerId = setTimeout(() => {
1436
1592
  signal?.removeEventListener("abort", onAbort);
1437
1593
  r();
1438
- }, ms || 0);
1594
+ }, delayDuration ? getMs2(delayDuration) : 0);
1439
1595
  });
1440
1596
  };
1441
1597
  const run2 = (left) => {
@@ -1444,18 +1600,22 @@ var Task;
1444
1600
  }
1445
1601
  return toPromise(task, signal).then((a) => {
1446
1602
  results.push(a);
1447
- if (left <= 1 || signal?.aborted) return results;
1603
+ if (left <= 1 || signal?.aborted) {
1604
+ return results;
1605
+ }
1448
1606
  return wait().then(() => run2(left - 1));
1449
1607
  });
1450
1608
  };
1451
1609
  return run2(times);
1452
1610
  });
1453
1611
  Task2.repeatUntil = (options) => (task) => (0, Task2.from)((signal) => {
1454
- const { when: predicate, delay: ms, maxAttempts } = options;
1612
+ const { when: predicate, delay: delayDuration, maxAttempts } = options;
1455
1613
  const wait = () => {
1456
- if (signal?.aborted) return Promise.resolve();
1614
+ if (signal?.aborted) {
1615
+ return Promise.resolve();
1616
+ }
1457
1617
  return new Promise((r) => {
1458
- let timerId = void 0;
1618
+ let timerId;
1459
1619
  const onAbort = () => {
1460
1620
  if (timerId !== void 0) {
1461
1621
  clearTimeout(timerId);
@@ -1468,7 +1628,7 @@ var Task;
1468
1628
  timerId = setTimeout(() => {
1469
1629
  signal?.removeEventListener("abort", onAbort);
1470
1630
  r();
1471
- }, ms || 0);
1631
+ }, delayDuration ? getMs2(delayDuration) : 0);
1472
1632
  });
1473
1633
  };
1474
1634
  const run2 = (attempt, lastValue) => {
@@ -1476,15 +1636,55 @@ var Task;
1476
1636
  return Promise.resolve(lastValue);
1477
1637
  }
1478
1638
  return toPromise(task, signal).then((a) => {
1479
- if (predicate(a)) return a;
1480
- if (maxAttempts !== void 0 && attempt >= maxAttempts) return a;
1481
- if (signal?.aborted) return a;
1639
+ if (predicate(a)) {
1640
+ return a;
1641
+ }
1642
+ if (maxAttempts !== void 0 && attempt >= maxAttempts) {
1643
+ return a;
1644
+ }
1645
+ if (signal?.aborted) {
1646
+ return a;
1647
+ }
1482
1648
  return wait().then(() => run2(attempt + 1, a));
1483
1649
  });
1484
1650
  };
1485
1651
  return run2(1);
1486
1652
  });
1487
- Task2.race = (tasks) => (0, Task2.from)((signal) => Promise.race(tasks.map((t) => toPromise(t, signal))));
1653
+ Task2.race = (tasks) => {
1654
+ if (tasks.length === 0) {
1655
+ return () => Deferred.fromPromise(new Promise(() => {
1656
+ }));
1657
+ }
1658
+ return (0, Task2.from)((outerSignal) => {
1659
+ const controllers = tasks.map(() => new AbortController());
1660
+ const onOuterAbort = () => {
1661
+ for (const ctrl of controllers) {
1662
+ ctrl.abort();
1663
+ }
1664
+ };
1665
+ if (outerSignal) {
1666
+ if (outerSignal.aborted) {
1667
+ onOuterAbort();
1668
+ } else {
1669
+ outerSignal.addEventListener("abort", onOuterAbort, { once: true });
1670
+ }
1671
+ }
1672
+ const promises = tasks.map((task, idx) => {
1673
+ const ctrl = controllers[idx];
1674
+ return toPromise(task, ctrl.signal).then((result) => {
1675
+ for (let i = 0; i < controllers.length; i++) {
1676
+ if (i !== idx) {
1677
+ controllers[i].abort();
1678
+ }
1679
+ }
1680
+ outerSignal?.removeEventListener("abort", onOuterAbort);
1681
+ return result;
1682
+ });
1683
+ });
1684
+ return Promise.race(promises);
1685
+ });
1686
+ };
1687
+ Task2.sequence = (tasks) => (0, Task2.from)((signal) => Promise.all(tasks.map((t) => toPromise(t, signal))));
1488
1688
  Task2.sequential = (tasks) => (0, Task2.from)(async (signal) => {
1489
1689
  const results = [];
1490
1690
  for (const task of tasks) {
@@ -1495,19 +1695,19 @@ var Task;
1495
1695
  }
1496
1696
  return results;
1497
1697
  });
1498
- Task2.timeout = (ms, onTimeout) => (task) => (0, Task2.from)((outerSignal) => {
1698
+ Task2.timeout = (duration, onTimeout) => (task) => (0, Task2.from)((outerSignal) => {
1499
1699
  const controller = new AbortController();
1500
1700
  let timerId;
1501
- const cleanUp = () => {
1701
+ function cleanUp() {
1502
1702
  if (timerId !== void 0) {
1503
1703
  clearTimeout(timerId);
1504
1704
  }
1505
1705
  outerSignal?.removeEventListener("abort", onOuterAbort);
1506
- };
1507
- const onOuterAbort = () => {
1706
+ }
1707
+ function onOuterAbort() {
1508
1708
  cleanUp();
1509
1709
  controller.abort();
1510
- };
1710
+ }
1511
1711
  if (outerSignal) {
1512
1712
  if (outerSignal.aborted) {
1513
1713
  controller.abort();
@@ -1520,12 +1720,12 @@ var Task;
1520
1720
  cleanUp();
1521
1721
  return Result.ok(a);
1522
1722
  }),
1523
- new Promise((resolve2) => {
1723
+ new Promise((res) => {
1524
1724
  timerId = setTimeout(() => {
1525
1725
  controller.abort();
1526
1726
  cleanUp();
1527
- resolve2(Result.error(onTimeout()));
1528
- }, ms);
1727
+ res(Result.err(onTimeout()));
1728
+ }, getMs2(duration));
1529
1729
  })
1530
1730
  ]);
1531
1731
  });
@@ -1553,14 +1753,19 @@ var Task;
1553
1753
  // src/Core/Resource.ts
1554
1754
  var Resource;
1555
1755
  ((Resource2) => {
1556
- Resource2.make = (acquire, release) => ({ acquire, release });
1756
+ Resource2.make = (acquire, release) => ({
1757
+ acquire,
1758
+ release
1759
+ });
1557
1760
  Resource2.fromTask = (acquire, release) => ({
1558
1761
  acquire: Task.map((a) => Result.ok(a))(acquire),
1559
1762
  release
1560
1763
  });
1561
1764
  Resource2.use = (f) => (resource) => Task.from(
1562
1765
  (signal) => Deferred.toPromise(resource.acquire(signal)).then(async (acquired) => {
1563
- if (Result.isError(acquired)) return acquired;
1766
+ if (Result.isErr(acquired)) {
1767
+ return acquired;
1768
+ }
1564
1769
  const a = acquired.value;
1565
1770
  try {
1566
1771
  const usageResult = await Deferred.toPromise(f(a)(signal));
@@ -1573,10 +1778,12 @@ var Resource;
1573
1778
  Resource2.combine = (resourceA, resourceB) => ({
1574
1779
  acquire: Task.from(
1575
1780
  (signal) => Deferred.toPromise(resourceA.acquire(signal)).then(async (acquiredA) => {
1576
- if (Result.isError(acquiredA)) return acquiredA;
1781
+ if (Result.isErr(acquiredA)) {
1782
+ return acquiredA;
1783
+ }
1577
1784
  const a = acquiredA.value;
1578
1785
  const acquiredB = await Deferred.toPromise(resourceB.acquire(signal));
1579
- if (Result.isError(acquiredB)) {
1786
+ if (Result.isErr(acquiredB)) {
1580
1787
  await Deferred.toPromise(resourceA.release(a)(signal));
1581
1788
  return acquiredB;
1582
1789
  }
@@ -1626,17 +1833,16 @@ var TaskMaybe;
1626
1833
  TaskMaybe2.some = (value) => Task.resolve(Maybe.some(value));
1627
1834
  TaskMaybe2.none = () => Task.resolve(Maybe.none());
1628
1835
  TaskMaybe2.fromMaybe = (option) => Task.resolve(option);
1836
+ TaskMaybe2.fromNullable = (value) => Task.resolve(Maybe.fromNullable(value));
1837
+ TaskMaybe2.fromResult = (result) => Task.resolve(Result.toMaybe(result));
1629
1838
  TaskMaybe2.fromTask = (task) => Task.map(Maybe.some)(task);
1630
- TaskMaybe2.tryCatch = (f) => Task.from(
1631
- (signal) => f(signal).then(Maybe.some).catch(() => Maybe.none())
1632
- );
1839
+ TaskMaybe2.tryCatch = (f) => Task.from((signal) => f(signal).then(Maybe.some).catch(() => Maybe.none()));
1633
1840
  TaskMaybe2.map = (f) => (data) => Task.map(Maybe.map(f))(data);
1634
1841
  TaskMaybe2.chain = (f) => (data) => Task.chain((option) => Maybe.isSome(option) ? f(option.value) : Task.resolve(Maybe.none()))(data);
1635
1842
  TaskMaybe2.ap = (arg) => (data) => Task.from(
1636
- (signal) => Promise.all([
1637
- Deferred.toPromise(data(signal)),
1638
- Deferred.toPromise(arg(signal))
1639
- ]).then(([of_, oa]) => Maybe.ap(oa)(of_))
1843
+ (signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
1844
+ ([of_, oa]) => Maybe.ap(oa)(of_)
1845
+ )
1640
1846
  );
1641
1847
  TaskMaybe2.fold = (onNone, onSome) => (data) => Task.map(Maybe.fold(onNone, onSome))(data);
1642
1848
  TaskMaybe2.match = (cases) => (data) => Task.map(Maybe.match(cases))(data);
@@ -1650,30 +1856,29 @@ var TaskMaybe;
1650
1856
  var TaskResult;
1651
1857
  ((TaskResult2) => {
1652
1858
  TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
1653
- TaskResult2.err = (error) => Task.resolve(Result.error(error));
1654
- TaskResult2.tryCatch = (f, onError) => Task.from(
1655
- (signal) => f(signal).then(Result.ok).catch((e) => Result.error(onError(e)))
1656
- );
1859
+ TaskResult2.err = (error) => Task.resolve(Result.err(error));
1860
+ TaskResult2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.err(onNull()) : Result.ok(value));
1861
+ TaskResult2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.err(onNone()) : Result.ok(maybe.value));
1862
+ TaskResult2.fromResult = (result) => Task.resolve(result);
1863
+ TaskResult2.fromThrowable = (f, onError) => (...args) => Task.from(() => f(...args).then(Result.ok).catch((error) => Result.err(onError(error))));
1864
+ TaskResult2.tryCatch = (f, onError) => Task.from((signal) => f(signal).then(Result.ok).catch((error) => Result.err(onError(error))));
1657
1865
  TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
1658
1866
  TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
1659
- TaskResult2.chain = (f) => (data) => Task.chain(
1660
- (result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.error(result.error))
1661
- )(
1867
+ TaskResult2.chain = (f) => (data) => Task.chain((result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.err(result.error)))(
1662
1868
  data
1663
1869
  );
1664
1870
  TaskResult2.fold = (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data);
1665
1871
  TaskResult2.match = (cases) => (data) => Task.map(Result.match(cases))(data);
1666
1872
  TaskResult2.recover = (fallback) => (data) => Task.chain(
1667
- (result) => Result.isError(result) ? fallback(result.error) : Task.resolve(result)
1873
+ (result) => Result.isErr(result) ? fallback(result.error) : Task.resolve(result)
1668
1874
  )(data);
1669
1875
  TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
1670
1876
  TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
1671
1877
  TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
1672
1878
  TaskResult2.ap = (arg) => (data) => Task.from(
1673
- (signal) => Promise.all([
1674
- Deferred.toPromise(data(signal)),
1675
- Deferred.toPromise(arg(signal))
1676
- ]).then(([of_, oa]) => Result.ap(oa)(of_))
1879
+ (signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
1880
+ ([of_, oa]) => Result.ap(oa)(of_)
1881
+ )
1677
1882
  );
1678
1883
  TaskResult2.run = (signal) => (task) => Deferred.toPromise(task(signal));
1679
1884
  })(TaskResult || (TaskResult = {}));
@@ -1681,97 +1886,97 @@ var TaskResult;
1681
1886
  // src/Core/Validation.ts
1682
1887
  var Validation;
1683
1888
  ((Validation2) => {
1684
- Validation2.valid = (value) => ({
1685
- kind: "Valid",
1686
- value
1687
- });
1688
- Validation2.invalid = (error) => ({
1689
- kind: "Invalid",
1690
- errors: [error]
1691
- });
1692
- Validation2.invalidAll = (errors) => ({
1693
- kind: "Invalid",
1694
- errors
1695
- });
1696
- Validation2.isValid = (data) => data.kind === "Valid";
1697
- Validation2.isInvalid = (data) => data.kind === "Invalid";
1698
- Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
1699
- Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
1889
+ Validation2.passed = (value) => ({ kind: "Passed", value });
1890
+ Validation2.failed = (error) => ({ kind: "Failed", errors: [error] });
1891
+ Validation2.failedAll = (errors) => ({ kind: "Failed", errors });
1892
+ Validation2.isPassed = (data) => data.kind === "Passed";
1893
+ Validation2.isFailed = (data) => data.kind === "Failed";
1894
+ Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.passed)(a) : (0, Validation2.failed)(onFalse(a));
1895
+ Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.failed)(onNull()) : (0, Validation2.passed)(value);
1896
+ Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.failed)(onNone()) : (0, Validation2.passed)(maybe.value);
1897
+ Validation2.map = (f) => (data) => (0, Validation2.isPassed)(data) ? (0, Validation2.passed)(f(data.value)) : data;
1898
+ Validation2.mapError = (f) => (data) => (0, Validation2.isFailed)(data) ? (0, Validation2.failedAll)(data.errors.map(f)) : data;
1700
1899
  Validation2.ap = (arg) => (data) => {
1701
- if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
1702
- const errors = [
1703
- ...(0, Validation2.isInvalid)(data) ? data.errors : [],
1704
- ...(0, Validation2.isInvalid)(arg) ? arg.errors : []
1705
- ];
1706
- return (0, Validation2.invalidAll)(errors);
1707
- };
1708
- Validation2.fold = (onInvalid, onValid) => (data) => (0, Validation2.isValid)(data) ? onValid(data.value) : onInvalid(data.errors);
1709
- Validation2.match = (cases) => (data) => (0, Validation2.isValid)(data) ? cases.valid(data.value) : cases.invalid(data.errors);
1710
- Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isValid)(data) ? data.value : defaultValue();
1900
+ if ((0, Validation2.isPassed)(data) && (0, Validation2.isPassed)(arg)) {
1901
+ return (0, Validation2.passed)(data.value(arg.value));
1902
+ }
1903
+ const errors = [...(0, Validation2.isFailed)(data) ? data.errors : [], ...(0, Validation2.isFailed)(arg) ? arg.errors : []];
1904
+ return (0, Validation2.failedAll)(errors);
1905
+ };
1906
+ Validation2.fold = (onFailed, onPassed) => (data) => (0, Validation2.isPassed)(data) ? onPassed(data.value) : onFailed(data.errors);
1907
+ Validation2.match = (cases) => (data) => (0, Validation2.isPassed)(data) ? cases.passed(data.value) : cases.failed(data.errors);
1908
+ Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isPassed)(data) ? data.value : defaultValue();
1711
1909
  Validation2.tap = (f) => (data) => {
1712
- if ((0, Validation2.isValid)(data)) f(data.value);
1910
+ if ((0, Validation2.isPassed)(data)) {
1911
+ f(data.value);
1912
+ }
1713
1913
  return data;
1714
1914
  };
1715
1915
  Validation2.tapError = (f) => (data) => {
1716
- if ((0, Validation2.isInvalid)(data)) f(data.errors);
1916
+ if ((0, Validation2.isFailed)(data)) {
1917
+ f(data.errors);
1918
+ }
1717
1919
  return data;
1718
1920
  };
1719
- Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
1720
- Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some(isBlocked) ? fallback() : data;
1721
- Validation2.toResult = (data) => (0, Validation2.isValid)(data) ? Result.ok(data.value) : Result.error(data.errors);
1722
- Validation2.toMaybe = (data) => (0, Validation2.isValid)(data) ? Maybe.some(data.value) : Maybe.none();
1723
- Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.valid)(data.value) : (0, Validation2.invalid)(data.error);
1921
+ Validation2.recover = (fallback) => (data) => (0, Validation2.isPassed)(data) ? data : fallback(data.errors);
1922
+ Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isFailed)(data) && !data.errors.some(isBlocked) ? fallback() : data;
1923
+ Validation2.toResult = (data) => (0, Validation2.isPassed)(data) ? Result.ok(data.value) : Result.err(data.errors);
1924
+ Validation2.toMaybe = (data) => (0, Validation2.isPassed)(data) ? Maybe.some(data.value) : Maybe.none();
1925
+ Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.passed)(data.value) : (0, Validation2.failed)(data.error);
1724
1926
  Validation2.product = (first, second) => {
1725
- if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
1726
- const errors = [
1727
- ...(0, Validation2.isInvalid)(first) ? first.errors : [],
1728
- ...(0, Validation2.isInvalid)(second) ? second.errors : []
1729
- ];
1730
- return (0, Validation2.invalidAll)(errors);
1927
+ if ((0, Validation2.isPassed)(first) && (0, Validation2.isPassed)(second)) {
1928
+ return (0, Validation2.passed)([first.value, second.value]);
1929
+ }
1930
+ const errors = [...(0, Validation2.isFailed)(first) ? first.errors : [], ...(0, Validation2.isFailed)(second) ? second.errors : []];
1931
+ return (0, Validation2.failedAll)(errors);
1731
1932
  };
1732
1933
  Validation2.productAll = (data) => {
1733
1934
  const values = [];
1734
1935
  const errors = [];
1735
1936
  for (const v of data) {
1736
- if ((0, Validation2.isValid)(v)) values.push(v.value);
1737
- else errors.push(...v.errors);
1937
+ if ((0, Validation2.isPassed)(v)) {
1938
+ values.push(v.value);
1939
+ } else {
1940
+ errors.push(...v.errors);
1941
+ }
1738
1942
  }
1739
- return errors.length > 0 ? (0, Validation2.invalidAll)(errors) : (0, Validation2.valid)(values);
1943
+ return errors.length > 0 ? (0, Validation2.failedAll)(errors) : (0, Validation2.passed)(values);
1740
1944
  };
1741
1945
  })(Validation || (Validation = {}));
1742
1946
 
1743
1947
  // src/Core/TaskValidation.ts
1744
1948
  var TaskValidation;
1745
1949
  ((TaskValidation2) => {
1746
- TaskValidation2.valid = (value) => Task.resolve(Validation.valid(value));
1747
- TaskValidation2.invalid = (error) => Task.resolve(Validation.invalid(error));
1748
- TaskValidation2.invalidAll = (errors) => Task.resolve(Validation.invalidAll(errors));
1950
+ TaskValidation2.passed = (value) => Task.resolve(Validation.passed(value));
1951
+ TaskValidation2.failed = (error) => Task.resolve(Validation.failed(error));
1952
+ TaskValidation2.failedAll = (errors) => Task.resolve(Validation.failedAll(errors));
1749
1953
  TaskValidation2.fromValidation = (validation) => Task.resolve(validation);
1750
- TaskValidation2.tryCatch = (f, onError) => Task.from(
1751
- (signal) => f(signal).then(Validation.valid).catch((e) => Validation.invalid(onError(e)))
1752
- );
1954
+ TaskValidation2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.failed(onNull()) : Validation.passed(value));
1955
+ TaskValidation2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Validation.failed(onNone()) : Validation.passed(maybe.value));
1956
+ TaskValidation2.fromResult = (result) => Task.resolve(Validation.fromResult(result));
1957
+ TaskValidation2.tryCatch = (f, onError) => Task.from((signal) => f(signal).then(Validation.passed).catch((error) => Validation.failed(onError(error))));
1753
1958
  TaskValidation2.map = (f) => (data) => Task.map(Validation.map(f))(data);
1754
1959
  TaskValidation2.ap = (arg) => (data) => Task.from(
1755
- (signal) => Promise.all([
1756
- Deferred.toPromise(data(signal)),
1757
- Deferred.toPromise(arg(signal))
1758
- ]).then(([vf, va]) => Validation.ap(va)(vf))
1960
+ (signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
1961
+ ([vf, va]) => Validation.ap(va)(vf)
1962
+ )
1759
1963
  );
1760
- TaskValidation2.fold = (onInvalid, onValid) => (data) => Task.map(Validation.fold(onInvalid, onValid))(data);
1964
+ TaskValidation2.fold = (onFailed, onPassed) => (data) => Task.map(Validation.fold(onFailed, onPassed))(data);
1761
1965
  TaskValidation2.match = (cases) => (data) => Task.map(Validation.match(cases))(data);
1762
1966
  TaskValidation2.getOrElse = (defaultValue) => (data) => Task.map(Validation.getOrElse(defaultValue))(data);
1763
1967
  TaskValidation2.tap = (f) => (data) => Task.map(Validation.tap(f))(data);
1764
1968
  TaskValidation2.recover = (fallback) => (data) => Task.chain(
1765
- (validation) => Validation.isValid(validation) ? Task.resolve(validation) : fallback(validation.errors)
1969
+ (validation) => Validation.isPassed(validation) ? Task.resolve(validation) : fallback(validation.errors)
1766
1970
  )(data);
1767
1971
  TaskValidation2.product = (first, second) => Task.from(
1768
- (signal) => Promise.all([
1769
- Deferred.toPromise(first(signal)),
1770
- Deferred.toPromise(second(signal))
1771
- ]).then(([va, vb]) => Validation.product(va, vb))
1972
+ (signal) => Promise.all([Deferred.toPromise(first(signal)), Deferred.toPromise(second(signal))]).then(
1973
+ ([va, vb]) => Validation.product(va, vb)
1974
+ )
1772
1975
  );
1773
1976
  TaskValidation2.productAll = (data) => Task.from(
1774
- (signal) => Promise.all(data.map((t) => Deferred.toPromise(t(signal)))).then((results) => Validation.productAll(results))
1977
+ (signal) => Promise.all(data.map((t) => Deferred.toPromise(t(signal)))).then(
1978
+ (results) => Validation.productAll(results)
1979
+ )
1775
1980
  );
1776
1981
  })(TaskValidation || (TaskValidation = {}));
1777
1982
 
@@ -1780,58 +1985,84 @@ var These;
1780
1985
  ((These2) => {
1781
1986
  These2.first = (value) => ({ kind: "First", first: value });
1782
1987
  These2.second = (value) => ({ kind: "Second", second: value });
1783
- These2.both = (first2, second2) => ({
1784
- kind: "Both",
1785
- first: first2,
1786
- second: second2
1787
- });
1988
+ These2.both = (f, s) => ({ kind: "Both", first: f, second: s });
1788
1989
  These2.isFirst = (data) => data.kind === "First";
1789
1990
  These2.isSecond = (data) => data.kind === "Second";
1790
1991
  These2.isBoth = (data) => data.kind === "Both";
1791
1992
  These2.hasFirst = (data) => data.kind === "First" || data.kind === "Both";
1792
1993
  These2.hasSecond = (data) => data.kind === "Second" || data.kind === "Both";
1793
1994
  These2.mapFirst = (f) => (data) => {
1794
- if ((0, These2.isSecond)(data)) return data;
1795
- if ((0, These2.isFirst)(data)) return (0, These2.first)(f(data.first));
1995
+ if ((0, These2.isSecond)(data)) {
1996
+ return data;
1997
+ }
1998
+ if ((0, These2.isFirst)(data)) {
1999
+ return (0, These2.first)(f(data.first));
2000
+ }
1796
2001
  return (0, These2.both)(f(data.first), data.second);
1797
2002
  };
1798
2003
  These2.mapSecond = (f) => (data) => {
1799
- if ((0, These2.isFirst)(data)) return data;
1800
- if ((0, These2.isSecond)(data)) return (0, These2.second)(f(data.second));
2004
+ if ((0, These2.isFirst)(data)) {
2005
+ return data;
2006
+ }
2007
+ if ((0, These2.isSecond)(data)) {
2008
+ return (0, These2.second)(f(data.second));
2009
+ }
1801
2010
  return (0, These2.both)(data.first, f(data.second));
1802
2011
  };
1803
2012
  These2.mapBoth = (onFirst, onSecond) => (data) => {
1804
- if ((0, These2.isSecond)(data)) return (0, These2.second)(onSecond(data.second));
1805
- if ((0, These2.isFirst)(data)) return (0, These2.first)(onFirst(data.first));
2013
+ if ((0, These2.isSecond)(data)) {
2014
+ return (0, These2.second)(onSecond(data.second));
2015
+ }
2016
+ if ((0, These2.isFirst)(data)) {
2017
+ return (0, These2.first)(onFirst(data.first));
2018
+ }
1806
2019
  return (0, These2.both)(onFirst(data.first), onSecond(data.second));
1807
2020
  };
1808
2021
  These2.chainFirst = (f) => (data) => {
1809
- if ((0, These2.isSecond)(data)) return data;
2022
+ if ((0, These2.isSecond)(data)) {
2023
+ return data;
2024
+ }
1810
2025
  return f(data.first);
1811
2026
  };
1812
2027
  These2.chainSecond = (f) => (data) => {
1813
- if ((0, These2.isFirst)(data)) return data;
2028
+ if ((0, These2.isFirst)(data)) {
2029
+ return data;
2030
+ }
1814
2031
  return f(data.second);
1815
2032
  };
1816
2033
  These2.fold = (onFirst, onSecond, onBoth) => (data) => {
1817
- if ((0, These2.isSecond)(data)) return onSecond(data.second);
1818
- if ((0, These2.isFirst)(data)) return onFirst(data.first);
2034
+ if ((0, These2.isSecond)(data)) {
2035
+ return onSecond(data.second);
2036
+ }
2037
+ if ((0, These2.isFirst)(data)) {
2038
+ return onFirst(data.first);
2039
+ }
1819
2040
  return onBoth(data.first, data.second);
1820
2041
  };
1821
2042
  These2.match = (cases) => (data) => {
1822
- if ((0, These2.isSecond)(data)) return cases.second(data.second);
1823
- if ((0, These2.isFirst)(data)) return cases.first(data.first);
2043
+ if ((0, These2.isSecond)(data)) {
2044
+ return cases.second(data.second);
2045
+ }
2046
+ if ((0, These2.isFirst)(data)) {
2047
+ return cases.first(data.first);
2048
+ }
1824
2049
  return cases.both(data.first, data.second);
1825
2050
  };
1826
2051
  These2.getFirstOrElse = (defaultValue) => (data) => (0, These2.hasFirst)(data) ? data.first : defaultValue();
1827
2052
  These2.getSecondOrElse = (defaultValue) => (data) => (0, These2.hasSecond)(data) ? data.second : defaultValue();
1828
2053
  These2.tap = (f) => (data) => {
1829
- if ((0, These2.hasFirst)(data)) f(data.first);
2054
+ if ((0, These2.hasFirst)(data)) {
2055
+ f(data.first);
2056
+ }
1830
2057
  return data;
1831
2058
  };
1832
2059
  These2.swap = (data) => {
1833
- if ((0, These2.isSecond)(data)) return (0, These2.first)(data.second);
1834
- if ((0, These2.isFirst)(data)) return (0, These2.second)(data.first);
2060
+ if ((0, These2.isSecond)(data)) {
2061
+ return (0, These2.first)(data.second);
2062
+ }
2063
+ if ((0, These2.isFirst)(data)) {
2064
+ return (0, These2.second)(data.first);
2065
+ }
1835
2066
  return (0, These2.both)(data.second, data.first);
1836
2067
  };
1837
2068
  })(These || (These = {}));