fold<R> method
Transforms the result based on its state using pattern matching.
onSuccess: Function to call with the value if this is a successonFailure: Function to call with the error message if this is a failure- Returns: The result of whichever function was called
Implementation
R fold<R>(R Function(T value) onSuccess, R Function(String error) onFailure) {
if (isSuccess) {
return onSuccess(_value as T);
} else {
return onFailure(_error!);
}
}