asyncFold<T> abstract method
Future<T>
asyncFold<T>({
- required AsyncSuccessCallback<
S, T> onSuccess, - required AsyncFailureCallback<
E, T> onFailure,
Asynchronous version of fold that handles Future operations in the success case.
This is particularly useful when the success transformation needs to perform asynchronous operations. The failure callback remains synchronous as error handling typically doesn't need to be async.
Example:
final result = Success(userId);
final userDetails = await result.asyncFold(
onSuccess: (id) async => await fetchUserDetails(id),
onFailure: (error) => UserDetails.empty(),
);
Implementation
Future<T> asyncFold<T>({
required AsyncSuccessCallback<S, T> onSuccess,
required AsyncFailureCallback<E, T> onFailure,
});