Hyperlinkv0.8.0-beta.28

Layer

Layer.updateServiceconsteffect/Layer.ts:1999
<I, A>(service: Context.Key<I, A>, f: (a: Types.NoInfer<A>) => A): <
  A1,
  E1,
  R1
>(
  layer: Layer<A1, E1, R1>
) => Layer<A1, E1, I | R1>
<A1, E1, R1, I, A>(
  layer: Layer<A1, E1, R1>,
  service: Context.Key<I, A>,
  f: (a: Types.NoInfer<A>) => A
): Layer<A1, E1, I | R1>

Updates a service in the context with a new implementation.

When to use

Use to adapt or extend a service's behavior during the creation of a layer.

Details

This function modifies the existing implementation of a service in the context. It retrieves the current service, applies the provided transformation function f, and replaces the old service with the transformed one.

providing services
Source effect/Layer.ts:199918 lines
export const updateService: {
  <I, A>(
    service: Context.Key<I, A>,
    f: (a: Types.NoInfer<A>) => A
  ): <A1, E1, R1>(layer: Layer<A1, E1, R1>) => Layer<A1, E1, I | R1>
  <A1, E1, R1, I, A>(
    layer: Layer<A1, E1, R1>,
    service: Context.Key<I, A>,
    f: (a: Types.NoInfer<A>) => A
  ): Layer<A1, E1, I | R1>
} = dual(
  3,
  <A1, E1, R1, I, A>(
    layer: Layer<A1, E1, R1>,
    service: Context.Key<I, A>,
    f: (a: Types.NoInfer<A>) => A
  ): Layer<A1, E1, I | R1> => provide(layer, effect(service, internalEffect.map(service, f)))
)