import type * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import type * as Scope from "effect/Scope"; /** * Builds a layer with the current scope. * @param layer - The layer to build. * @returns A scoped effect returning a Context with the provided layer. */ export const buildLayerScoped = ( layer: Layer.Layer, ): Effect.Effect, E, RIn | Scope.Scope> => Effect.flatMap(Effect.scope, (scope) => Layer.buildWithScope(layer, scope)); /** * Builds a layer with the current scope and provides it to the given effect. * @param layer - The layer to build. */ export const provideLayerScoped = (layer: Layer.Layer) => (effect: Effect.Effect) => Effect.flatMap(buildLayerScoped(layer), (context) => Effect.provideContext(effect, context), );