fold<R> method
Method to handle both success and failure cases
Implementation
FutureOr<R> fold<R>(
{required FutureOr<R> Function(S value) onSuccess,
required FutureOr<R> Function(ResendError? error, String? message)
onFailure}) async {
// If the result is a success, call the onSuccess function with the value
if (this is ResendSuccess) {
return await onSuccess((this as ResendSuccess<S>).value);
}
// If the result is a failure, call the onFailure function with the status code, message, and error
else if (this is ResendFailure) {
return await onFailure(
(this as ResendFailure<S>).error, (this as ResendFailure<S>).message);
}
// Throw an exception if the result type is unexpected
else {
throw Exception('Unexpected result type');
}
}