Hyperlinkv0.8.0-beta.28

Layer

Layer.tapconsteffect/Layer.ts:1637
<ROut, XR extends ROut, RIn2, E2, X>(
  f: (context: Context.Context<XR>) => Effect<X, E2, RIn2>
): <RIn, E>(
  self: Layer<ROut, E, RIn>
) => Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>
<RIn, E, ROut, XR extends ROut, RIn2, E2, X>(
  self: Layer<ROut, E, RIn>,
  f: (context: Context.Context<XR>) => Effect<X, E2, RIn2>
): Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>

Performs the specified effect if this layer succeeds.

When to use

Use to run an effectful observation after a layer has been built successfully, such as logging or metrics, without changing the services the layer provides.

Details

The callback receives the services produced by this layer. Its result is discarded, and the original layer output is preserved.

Source effect/Layer.ts:163718 lines
export const tap: {
  <ROut, XR extends ROut, RIn2, E2, X>(
    f: (context: Context.Context<XR>) => Effect<X, E2, RIn2>
  ): <RIn, E>(self: Layer<ROut, E, RIn>) => Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>
  <RIn, E, ROut, XR extends ROut, RIn2, E2, X>(
    self: Layer<ROut, E, RIn>,
    f: (context: Context.Context<XR>) => Effect<X, E2, RIn2>
  ): Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>>
} = dual(2, <RIn, E, ROut, XR extends ROut, RIn2, E2, X>(
  self: Layer<ROut, E, RIn>,
  f: (context: Context.Context<XR>) => Effect<X, E2, RIn2>
): Layer<ROut, E | E2, RIn | Exclude<RIn2, Scope.Scope>> =>
  fromBuild((memoMap, scope) =>
    internalEffect.flatMap(
      self.build(memoMap, scope),
      (context) => Scope.provide(internalEffect.as(f(context as Context.Context<XR>), context), scope)
    )
  ))