Hyperlinkv0.8.0-beta.28

Stream

Stream.mapErrorconsteffect/Stream.ts:5779
<E, E2>(f: (error: E) => E2): <A, R>(
  self: Stream<A, E, R>
) => Stream<A, E2, R>
<A, E, R, E2>(self: Stream<A, E, R>, f: (error: E) => E2): Stream<
  A,
  E2,
  R
>

Transforms the errors emitted by this stream using f.

Example (Mapping stream errors)

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

const program = Effect.gen(function*() {
  const result = yield* Stream.fail("bad").pipe(
    Stream.mapError((error) => `mapped: ${error}`),
    Stream.catch((error) => Stream.make(`recovered from ${error}`)),
    Stream.runCollect
  )
  yield* Console.log(result)
})

Effect.runPromise(program)
// Output: [ "recovered from mapped: bad" ]
error handling
Source effect/Stream.ts:57797 lines
export const mapError: {
  <E, E2>(f: (error: E) => E2): <A, R>(self: Stream<A, E, R>) => Stream<A, E2, R>
  <A, E, R, E2>(self: Stream<A, E, R>, f: (error: E) => E2): Stream<A, E2, R>
} = dual(2, <A, E, R, E2>(
  self: Stream<A, E, R>,
  f: (error: E) => E2
): Stream<A, E2, R> => fromChannel(Channel.mapError(self.channel, f)))
Referenced by 1 symbols