mini-effect 0.0.4 → 0.0.5

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.
@@ -10,6 +10,7 @@ declare const succeed: <R$1>(result: R$1) => Effect<R$1, never>;
10
10
  declare const catchSome: <T = any, C = any, CE = any>(thunk: (cause: unknown) => Effect<T, C> | undefined) => WrapEffect<T, C, CE>;
11
11
  declare const gen: <T extends Effect<any, any>, TReturn, TNext>(thunk: (signal: AbortSignal) => Generator<T, TReturn, TNext>) => Effect<TReturn, inferError<T>>;
12
12
  declare const pipe: <F extends Effect, P$1 extends [Pipeable, ...Pipeable[]]>(first: F, ...pipeable: PipeReturn<[F, ...P$1]> extends never ? never : P$1) => PipeReturn<[F, ...P$1]>;
13
+ declare const retry: <R$1 extends number | "forever", T, C>(times: R$1, effect: Effect<T, C>) => Effect<T, R$1 extends "forever" ? never : C>;
13
14
  declare class Effect<T = any, C = any> {
14
15
  [RUN]?: (signal: AbortSignal) => T | PromiseLike<T>;
15
16
  [ERROR]?: (cause: unknown) => Effect | undefined;
@@ -38,4 +39,4 @@ type IsNever<T> = [T] extends [never] ? true : false;
38
39
  type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
39
40
  type ExtendsStrict<Left, Right> = IsAny<Left | Right> extends true ? true : IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false;
40
41
  //#endregion
41
- export { Effect, Pipeable, PipeableThunk, Thunk, WrapEffect, run as _run, run, catchSome, fail, fn, gen, inferError, inferExclude, inferInput, inferReturn, pipe, succeed };
42
+ export { Effect, Pipeable, PipeableThunk, Thunk, WrapEffect, run as _run, run, catchSome, fail, fn, gen, inferError, inferExclude, inferInput, inferReturn, pipe, retry, succeed };
@@ -45,6 +45,10 @@ const pipe = (first, ...pipeable) => {
45
45
  return next;
46
46
  });
47
47
  };
48
+ const retry = (times, effect) => {
49
+ let step = 0;
50
+ return effect.pipe(catchSome((cause) => typeof times === "number" && ++step > times ? fail(cause) : effect));
51
+ };
48
52
  var Effect = class {
49
53
  [RUN];
50
54
  [ERROR];
@@ -97,4 +101,4 @@ var WrapEffect = class {
97
101
  };
98
102
 
99
103
  //#endregion
100
- export { Effect, WrapEffect, run as _run, run, catchSome, fail, fn, gen, pipe, succeed };
104
+ export { Effect, WrapEffect, run as _run, run, catchSome, fail, fn, gen, pipe, retry, succeed };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mini-effect",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "description": "A mini-effect library for TypeScript.",
6
6
  "author": "Jacob Ebey <jacob.ebey@live.com>",
7
7
  "license": "MIT",