then<S2> method

ResultStream<S2, F> then<S2>(
  1. FutureOr<Result<S2, F>> run(
    1. S success
    )
)

Runs a function that returns a Result with each success value. Failures skip it.

Steps run one at a time, like Stream.asyncMap: the source is paused while a step runs, and the output keeps input order, failures included.

Implementation

ResultStream<S2, F> then<S2>(
  FutureOr<Result<S2, F>> Function(S success) run,
) => ResultStream(
  () => this.run().asyncMap(
    (r) => switch (r) {
      Success(:final value) => run(value),
      final Failure<S, F> f => f.retype(),
    },
  ),
);