unwrap method

T unwrap()

Returns the contained ok value.

Because this function may panic, its use is generally discouraged. Instead, prefer to use pattern matching and handle the error case explicitly, or call unwrapOr or unwrapOrElse.

Example

Basic Usage

import 'package:dartsult/dartsult.dart';

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

  x = Result.error("emergency failure");
  try {
    x.unwrap();
  } catch(e) {
    assert(e.toString() == "Null check operator used on a null value");
  }
}

Implementation

T unwrap() => _ok.val!;