asyncMap<T> method
Transforms the successful value inside the Result asynchronously.
If the current Result is a success, the transform function is applied
to its value, wrapping the new value in a SuccessResult.
If the current Result is already a failure, the transform step is skipped,
and the failure is forwarded downstream.
Example:
Future<Result<int>> idResult = fetchUser().asyncMap((user) => user.id);
Implementation
Future<Result<T>> asyncMap<T>(FutureOr<T> Function(S value) transform) async {
final result = await this;
return switch (result) {
SuccessResult<S>(success: Success(:final value)) =>
Result.success(await transform(value)),
FailureResult<S>(failure: final failure) => Result.failure(failure),
};
}