fold method

  1. @override
Result<Object> fold(
  1. @noFutures Result<Object>? onOk(
    1. Ok<T> ok
    ),
  2. @noFutures Result<Object>? onErr(
    1. Err<T> err
    )
)
override

Folds the two cases of this Result into a single new Result.

Implementation

@override
@pragma('vm:prefer-inline')
Result<Object> fold(
  @noFutures Result<Object>? Function(Ok<T> ok) onOk,
  @noFutures Result<Object>? Function(Err<T> err) onErr,
) {
  try {
    return onErr(this) ?? this;
  } catch (error, stackTrace) {
    return Err(error, stackTrace: stackTrace);
  }
}