import * as Context from "../Context.ts" import type { Effect } from "../Effect.ts" import { dual } from "../Function.ts" import * as Layer from "../Layer.ts" import { isEffect } from "./core.ts" import * as effect from "./effect.ts" const provideLayer = ( self: Effect, layer: Layer.Layer, options?: { readonly local?: boolean | undefined } | undefined ): Effect> => effect.scopedWith((scope) => effect.flatMap( options?.local ? Layer.buildWithMemoMap(layer, Layer.makeMemoMapUnsafe(), scope) : Layer.buildWithScope(layer, scope), (context) => effect.provideContext(self, context) ) ) /** @internal */ export const provide = dual< { ]>( layers: Layers, options?: { readonly local?: boolean | undefined } | undefined ): ( self: Effect ) => Effect< A, E | Layer.Error, | Layer.Services | Exclude> > ( layer: Layer.Layer, options?: { readonly local?: boolean | undefined } | undefined ): (self: Effect) => Effect> (context: Context.Context): (self: Effect) => Effect> }, { ]>( self: Effect, layers: Layers, options?: { readonly local?: boolean | undefined } | undefined ): Effect< A, E | Layer.Error, | Layer.Services | Exclude> > ( self: Effect, layer: Layer.Layer, options?: { readonly local?: boolean | undefined } | undefined ): Effect> ( self: Effect, context: Context.Context ): Effect> } >( (args) => isEffect(args[0]), ( self: Effect, source: | Layer.Layer | Context.Context | Array, options?: { readonly local?: boolean | undefined } | undefined ): Effect> => Context.isContext(source) ? effect.provideContext(self, source) : provideLayer(self, Array.isArray(source) ? Layer.mergeAll(...source as any) : source, options) )