Skip to main content

Overview

Maps a ResultAsync<T, E> to ResultAsync<U, E> by applying a function to the contained Ok value. The Err value is left untouched.

Signature

(t: T) => A | Promise<A>
required
Function to transform the Ok value. Can return either a value or a Promise.
Returns: ResultAsync<A, E> - A new ResultAsync with the transformed value

Usage

Basic transformation

Async transformation

Error handling

Key characteristics

The mapping function can be either synchronous or asynchronous with no impact on the return type - both return ResultAsync.
  • Short-circuits on Err: If the ResultAsync is an Err, map is not executed
  • Type safety: The transformed type is tracked through the chain
  • Async support: Can handle both sync and async transformation functions

mapErr

Transform the error value

andThen

Chain operations that return Results