method Stream.mapErr
Stream.mapErr<F>(fn: (error: E) => Promisable<F>): Stream<T, F>

Similar to Array.prototype.map, but works on the stream of errors. If the provided function throws an error or returns a rejected promise, the new error will be collected and emitted as an error result in the stream.

Examples

Example 1

import { Stream } from "anabranch";

const stream = Source.from<number, string>(async function* () {
  yield 1;
  yield 2;
});

const mappedErrorStream = stream.mapErr(async (error) => {
  return `Mapped error: ${error}`;
});

Type Parameters

Parameters

fn: (error: E) => Promisable<F>

Return Type

Stream<T, F>

See

Usage

import { type Stream } from ".";