Overview
Extracts theOk value from a ResultAsync, or returns the provided default value if it’s an Err. Returns a Promise of the value.
Signature
The default value to return if the ResultAsync is an Err
Promise<T | A> - A Promise resolving to the Ok value or the default
Usage
Basic usage
Configuration with defaults
API responses
Chaining with transformations
Key characteristics
- Always succeeds: Never throws, always returns a value
- Type safety: Return type is union of Ok and default types
- Returns Promise: Requires await or .then() to access the value
When to use
- At application boundaries where you need concrete values
- When a sensible default exists for error cases
- Converting Result-based code to traditional async code
Related
match
Handle both cases with callbacks
orElse
Compute default based on the error