Overview
Chains operations on aResultAsync, where the next operation depends on the success of the previous one. The callback must return a Result or ResultAsync.
Signature
Function that takes the Ok value and returns a new Result or ResultAsync
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
Resultand asyncResultAsync
Related
map
Transform without changing Result structure
orElse
Handle errors in the chain