Skip to main content

Why Combine Results?

When you have multiple independent operations that all need to succeed, combine provides a cleaner alternative to nested checks:

Result.combine Basics

Combining Homogeneous Results

combine takes an array of Results with the same type:
If any Result is an Err, combine short-circuits and returns the first error:

Combining Heterogeneous Results

Combine Results of different types using tuples:
Arrays are preserved (not flattened):

Real-World Example: Form Validation

Validate multiple form fields independently:
1

Define validation functions

2

Combine validations

3

Handle the result

Getting All Errors with combineWithAllErrors

Instead of short-circuiting at the first error, collect ALL errors:
This is perfect for form validation where you want to show all errors at once:

Combining Async Results

Use ResultAsync.combine for asynchronous operations:

Collecting All Async Errors

Pattern: Dependent vs Independent Operations

When operations don’t depend on each other, use combine:

Advanced: Partial Success Handling

Sometimes you want to proceed even if some operations fail:

Real-World Example: Configuration Loading

Load and validate configuration from multiple sources:

Next Steps

Error Recovery

Learn advanced error handling with orElse and match

Async Operations

Master asynchronous operations with ResultAsync