Skip to main content

Overview

Chains operations on a ResultAsync, where the next operation depends on the success of the previous one. The callback must return a Result or ResultAsync.

Signature

(t: T) => Result<U, F> | ResultAsync<U, F>
required
Function that takes the Ok value and returns a new Result or ResultAsync
Returns: ResultAsync<U, E | F> - A new ResultAsync with combined error types

Usage

Sequential async operations

Mixing sync and async

Flattening nested Results

Key characteristics

Unlike map, andThen can introduce new error types. The resulting error type is the union of all possible errors.
  • Error propagation: Short-circuits if any operation fails
  • Type unions: Combines error types from all operations
  • Flexible: Accepts both sync Result and async ResultAsync

map

Transform without changing Result structure

orElse

Handle errors in the chain