expectOk<T> function

T expectOk<T>(
  1. Result<T> result, {
  2. String? because,
})

Plain-throw assertion helpers (dependency-light: AssertionError is dart:core, no test/matcher import). Consumers get the same unwrap-or-fail ergonomics in every test without per-test boilerplate. Assert result is Ok and return its value; throws otherwise.

Implementation

/// Assert [result] is [Ok] and return its value; throws otherwise.
T expectOk<T>(Result<T> result, {String? because}) => switch (result) {
  Ok<T>(:final value) => value,
  Err<T>(:final problem) => throw AssertionError(
    'expected Ok but got Err(${problem.type}, ${problem.status})'
    '${because == null ? '' : ' — $because'}',
  ),
};