Hyperlinkv0.8.0-beta.28

Stream

Stream.tapCauseconsteffect/Stream.ts:4986
<E, A2, E2, R2>(
  f: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>
): <A, R>(self: Stream<A, E, R>) => Stream<A, E | E2, R2 | R>
<A, E, R, A2, E2, R2>(
  self: Stream<A, E, R>,
  f: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>
): Stream<A, E | E2, R | R2>

Runs an effect when the stream fails without changing its values or error, unless the tap effect itself fails.

Example (Tapping stream causes)

import { Cause, Console, Effect, Stream } from "effect"

const stream = Stream.make(1, 2).pipe(
  Stream.concat(Stream.fail("boom")),
  Stream.tapCause((cause) => Console.log(Cause.isReason(cause))),
  Stream.catch(() => Stream.succeed(0))
)

const program = Effect.gen(function* () {
  const result = yield* Stream.runCollect(stream)
  yield* Console.log(result)
})

Effect.runPromise(program)
// Output: true
// Output: [ 1, 2, 0 ]
error handling
Source effect/Stream.ts:498616 lines
export const tapCause: {
  <E, A2, E2, R2>(
    f: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>
  ): <A, R>(self: Stream<A, E, R>) => Stream<A, E | E2, R2 | R>
  <A, E, R, A2, E2, R2>(
    self: Stream<A, E, R>,
    f: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>
  ): Stream<A, E | E2, R | R2>
} = dual(2, <A, E, R, A2, E2, R2>(
  self: Stream<A, E, R>,
  f: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>
): Stream<A, E | E2, R | R2> =>
  self.channel.pipe(
    Channel.tapCause(f),
    fromChannel
  ))