method Stream.recover
Stream.recover<U>(fn: (error: E) => Promisable<U>): Stream<T | U, never>

Recovers from all errors by applying the provided function to transform them into successful values. This allows you to handle all errors gracefully while still collecting successful values in the stream.

Examples

Example 1

import { Stream } from "anabranch";

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

const recoveredStream = stream.recover(e => 0);

Type Parameters

Parameters

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

Return Type

Stream<T | U, never>

Usage

import { type Stream } from ".";