Skip to main content

Overview

Executes one of two functions depending on whether the ResultAsync is Ok or Err. Always returns a Promise that resolves to the result of the executed function.

Signature

(value: T) => A
required
Function to execute if the ResultAsync is Ok
(error: E) => B
required
Function to execute if the ResultAsync is Err
Returns: Promise<A | B> - A Promise resolving to the result of the executed callback

Usage

HTTP response handling

Logging results

Converting to traditional error handling

Key characteristics

Unlike the sync Result.match(), ResultAsync.match() always returns a Promise, even if both callbacks are synchronous.
  • Exhaustive: Forces you to handle both Ok and Err cases
  • Type unwrapping: Extracts the value/error from the Result
  • Returns Promise: Always async, requires await or .then()

Comparison with sync Result

unwrapOr

Get value or default without error callback

Result.match

Synchronous version