fold<R> method

R fold<R>({
  1. required R onSuccess(
    1. T value
    ),
  2. required R onFailure(
    1. ConversionException error
    ),
})

Reduces this result to a single value by handling both outcomes explicitly.

Both callbacks are required, ensuring exhaustive handling. This is the recommended way to consume results when you need to act on failures.

Implementation

R fold<R>({
  required R Function(T value) onSuccess,
  required R Function(ConversionException error) onFailure,
}) {
  if (isSuccess) return onSuccess(_value as T);
  return onFailure(_error!);
}