fold<T> abstract method
T
fold<T>({
- required SyncSuccessCallback<
S, T> onSuccess, - required SyncFailureCallback<
E, T> onFailure,
Transforms this result into a value of type T
by applying the appropriate callback
based on whether this is a success or failure.
This method only accepts synchronous callbacks. For async operations, use asyncFold.
Example:
final result = Success(42);
final string = result.fold(
onSuccess: (value) => 'Success: $value',
onFailure: (error) => 'Error: ${error.message}',
);
Implementation
T fold<T>({
required SyncSuccessCallback<S, T> onSuccess,
required SyncFailureCallback<E, T> onFailure,
});