Skip to content

Commit

Permalink
remove FnEffect type to improve return type of Effect.fn (#4107)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Dec 10, 2024
1 parent 22905cf commit 1e59e4f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-sheep-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

remove FnEffect type to improve return type of Effect.fn
88 changes: 68 additions & 20 deletions packages/effect/src/Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9783,31 +9783,37 @@ export declare namespace Service {
* @category models
*/
export namespace fn {
/**
* @since 3.11.0
* @category models
*/
export type FnEffect<AEff, Eff extends YieldWrap<Effect<any, any, any>>> = Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>

/**
* @since 3.11.0
* @category models
*/
export type Gen = {
<Eff extends YieldWrap<Effect<any, any, any>>, AEff, Args extends Array<any>>(
body: (...args: Args) => Generator<Eff, AEff, never>
): (...args: Args) => fn.FnEffect<AEff, Eff>
): (...args: Args) => Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>
<Eff extends YieldWrap<Effect<any, any, any>>, AEff, Args extends Array<any>, A extends Effect<any, any, any>>(
body: (...args: Args) => Generator<Eff, AEff, never>,
a: (_: fn.FnEffect<AEff, Eff>) => A
a: (
_: Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>
) => A
): (...args: Args) => A
<Eff extends YieldWrap<Effect<any, any, any>>, AEff, Args extends Array<any>, A, B extends Effect<any, any, any>>(
body: (...args: Args) => Generator<Eff, AEff, never>,
a: (_: fn.FnEffect<AEff, Eff>) => A,
a: (
_: Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>
) => A,
b: (_: A) => B
): (...args: Args) => B
<
Expand All @@ -9819,7 +9825,13 @@ export namespace fn {
C extends Effect<any, any, any>
>(
body: (...args: Args) => Generator<Eff, AEff, never>,
a: (_: fn.FnEffect<AEff, Eff>) => A,
a: (
_: Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>
) => A,
b: (_: A) => B,
c: (_: B) => C
): (...args: Args) => C
Expand All @@ -9833,7 +9845,13 @@ export namespace fn {
D extends Effect<any, any, any>
>(
body: (...args: Args) => Generator<Eff, AEff, never>,
a: (_: fn.FnEffect<AEff, Eff>) => A,
a: (
_: Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>
) => A,
b: (_: A) => B,
c: (_: B) => C,
d: (_: C) => D
Expand All @@ -9849,7 +9867,13 @@ export namespace fn {
E extends Effect<any, any, any>
>(
body: (...args: Args) => Generator<Eff, AEff, never>,
a: (_: fn.FnEffect<AEff, Eff>) => A,
a: (
_: Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>
) => A,
b: (_: A) => B,
c: (_: B) => C,
d: (_: C) => D,
Expand All @@ -9867,7 +9891,13 @@ export namespace fn {
F extends Effect<any, any, any>
>(
body: (...args: Args) => Generator<Eff, AEff, never>,
a: (_: fn.FnEffect<AEff, Eff>) => A,
a: (
_: Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>
) => A,
b: (_: A) => B,
c: (_: B) => C,
d: (_: C) => D,
Expand All @@ -9887,7 +9917,13 @@ export namespace fn {
G extends Effect<any, any, any>
>(
body: (...args: Args) => Generator<Eff, AEff, never>,
a: (_: fn.FnEffect<AEff, Eff>) => A,
a: (
_: Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>
) => A,
b: (_: A) => B,
c: (_: B) => C,
d: (_: C) => D,
Expand All @@ -9909,7 +9945,13 @@ export namespace fn {
H extends Effect<any, any, any>
>(
body: (...args: Args) => Generator<Eff, AEff, never>,
a: (_: fn.FnEffect<AEff, Eff>) => A,
a: (
_: Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>
) => A,
b: (_: A) => B,
c: (_: B) => C,
d: (_: C) => D,
Expand All @@ -9933,7 +9975,13 @@ export namespace fn {
I extends Effect<any, any, any>
>(
body: (...args: Args) => Generator<Eff, AEff, never>,
a: (_: fn.FnEffect<AEff, Eff>) => A,
a: (
_: Effect<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect<infer _A, infer _E, infer R>>] ? R : never
>
) => A,
b: (_: A) => B,
c: (_: B) => C,
d: (_: C) => D,
Expand Down

0 comments on commit 1e59e4f

Please sign in to comment.