unwrapOr method

T unwrapOr(
  1. T instance
)

Returns the contained ok value or a provided default.

Arguments passed to unwrapOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrapOrElse, which is lazily evaluated.

Example

Basic Usage:

import 'package:dartsult/dartsult.dart';

main() {
  int defaultt = 2;
  Result<int, String> x = Result.ok(9);
  assert(x.unwrapOr(defaultt) == 9);

  x = Result.error("error");
  assert(x.unwrapOr(defaultt) == defaultt);
}

Implementation

T unwrapOr(T instance) => _ok.val != null ? _ok.val! : instance;