Skip to content

Commit

Permalink
fix circular
Browse files Browse the repository at this point in the history
  • Loading branch information
maksim.khramtsov authored and tim-smart committed Aug 20, 2024
1 parent f304bab commit ac747a0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 69 deletions.
2 changes: 1 addition & 1 deletion packages/effect/src/Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3603,7 +3603,7 @@ export const bindAll: {
| Effect.Error<All.ReturnObject<X, All.IsDiscard<O>, All.ExtractMode<O>>>,
R1 | Effect.Context<X[keyof X]>
>
} = effect.bindAll
} = circular.bindAll

/**
* The "do simulation" in Effect allows you to write code in a more declarative style, similar to the "do notation" in other programming languages. It provides a way to define variables and perform operations on them using functions like `bind` and `let`.
Expand Down
69 changes: 1 addition & 68 deletions packages/effect/src/internal/core-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as Chunk from "../Chunk.js"
import * as Clock from "../Clock.js"
import * as Context from "../Context.js"
import * as Duration from "../Duration.js"
import * as Effect from "../Effect.js"
import type * as Effect from "../Effect.js"
import type * as Fiber from "../Fiber.js"
import type * as FiberId from "../FiberId.js"
import type * as FiberRef from "../FiberRef.js"
Expand Down Expand Up @@ -407,73 +407,6 @@ export const let_: {
): Effect.Effect<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }, E, R>
} = doNotation.let_<Effect.EffectTypeLambda>(core.map)

/* @internal */
export const bindAll: {
<A extends object, X extends Record<string, Effect.Effect<any, any, any>>, O extends Effect.All.Options>(
f: (a: A) => [Extract<keyof X, keyof A>] extends [never] ? X : `Duplicate keys`,
options?: undefined | O
): <E1, R1>(self: Effect.Effect<A, E1, R1>) => Effect.Effect<
{
[K in keyof X | keyof A]: K extends keyof A ? A[K] :
K extends keyof Effect.Effect.Success<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
> ? Effect.Effect.Success<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
>[K] :
never
},
| E1
| Effect.Effect.Error<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
>,
R1 | Effect.Effect.Context<X[keyof X]>
>
<
A extends object,
X extends Record<string, Effect.Effect<any, any, any>>,
O extends Effect.All.Options,
E1,
R1
>(
self: Effect.Effect<A, E1, R1>,
f: (a: A) => [Extract<keyof X, keyof A>] extends [never] ? X : `Duplicate keys`,
options?: undefined | Effect.All.Options
): Effect.Effect<
{
[K in keyof X | keyof A]: K extends keyof A ? A[K] :
K extends keyof Effect.Effect.Success<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
> ? Effect.Effect.Success<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
>[K] :
never
},
| E1
| Effect.Effect.Error<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
>,
R1 | Effect.Effect.Context<X[keyof X]>
>
} = dual((args) => core.isEffect(args[0]), <
A extends object,
X extends Record<string, Effect.Effect<any, any, any>>,
O extends Effect.All.Options,
E1,
R1
>(
self: Effect.Effect<A, E1, R1>,
f: (a: A) => X,
options?: undefined | O
) =>
Effect.flatMap(
self,
(a) =>
(Effect.all(f(a), options) as Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>)
.pipe(
Effect.map((record) => Object.assign({}, a, record))
)
))

/* @internal */
export const dropUntil: {
<A, E, R>(
Expand Down
71 changes: 71 additions & 0 deletions packages/effect/src/internal/effect/circular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,74 @@ export const zipWithFiber = dual<
return pipeArguments(this, arguments)
}
}))

/* @internal */
export const bindAll: {
<A extends object, X extends Record<string, Effect.Effect<any, any, any>>, O extends Effect.All.Options>(
f: (a: A) => [Extract<keyof X, keyof A>] extends [never] ? X : `Duplicate keys`,
options?: undefined | O
): <E1, R1>(self: Effect.Effect<A, E1, R1>) => Effect.Effect<
{
[K in keyof X | keyof A]: K extends keyof A ? A[K] :
K extends keyof Effect.Effect.Success<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
> ? Effect.Effect.Success<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
>[K] :
never
},
| E1
| Effect.Effect.Error<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
>,
R1 | Effect.Effect.Context<X[keyof X]>
>
<
A extends object,
X extends Record<string, Effect.Effect<any, any, any>>,
O extends Effect.All.Options,
E1,
R1
>(
self: Effect.Effect<A, E1, R1>,
f: (a: A) => [Extract<keyof X, keyof A>] extends [never] ? X : `Duplicate keys`,
options?: undefined | Effect.All.Options
): Effect.Effect<
{
[K in keyof X | keyof A]: K extends keyof A ? A[K] :
K extends keyof Effect.Effect.Success<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
> ? Effect.Effect.Success<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
>[K] :
never
},
| E1
| Effect.Effect.Error<
Effect.All.ReturnObject<X, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
>,
R1 | Effect.Effect.Context<X[keyof X]>
>
} = dual((args) => core.isEffect(args[0]), <
A extends object,
X extends Record<string, Effect.Effect<any, any, any>>,
O extends Effect.All.Options,
E1,
R1
>(
self: Effect.Effect<A, E1, R1>,
f: (a: A) => X,
options?: undefined | O
) =>
core.flatMap(
self,
(a) =>
(fiberRuntime.all(f(a), options) as Effect.All.ReturnObject<
X,
Effect.All.IsDiscard<O>,
Effect.All.ExtractMode<O>
>)
.pipe(
core.map((record) => Object.assign({}, a, record))
)
))

0 comments on commit ac747a0

Please sign in to comment.