-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
54 lines (52 loc) · 1.56 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Effect } from "effect";
import type { YieldWrap } from "effect/Utils";
type InferE<Eff extends YieldWrap<Effect.Effect<any, any, any>>> = [
Eff,
] extends [never]
? never
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>]
? E
: never;
type InferR<Eff extends YieldWrap<Effect.Effect<any, any, any>>> = [
Eff,
] extends [never]
? never
: [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>]
? R
: never;
export function effect<
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
AEff,
>(
f: () => Generator<Eff, AEff, never>,
): Effect.Effect<AEff, InferE<Eff>, InferR<Eff>>;
export function effect<
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
AEff,
Args extends any[],
>(
f: (...args: Args) => Generator<Eff, AEff, never>,
): (...args: Args) => Effect.Effect<AEff, InferE<Eff>, InferR<Eff>>;
export function effect<
Self,
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
AEff,
>(
self: Self,
f: (this: Self) => Generator<Eff, AEff, never>,
): Effect.Effect<AEff, InferE<Eff>, InferR<Eff>>;
export function effect<
Eff extends YieldWrap<Effect.Effect<any, any, any>>,
AEff,
Args extends any[],
Self,
>(
self: Self,
f: (this: Self, ...args: Args) => Generator<Eff, AEff, never>,
): (...args: Args) => Effect.Effect<AEff, InferE<Eff>, InferR<Eff>>;
export function effect() {
const f =
arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0]);
if (f.length === 0) return Effect.gen(f);
return (...args: any) => Effect.gen(() => f(...args));
}