expect method

T expect()

Expects the snapshot to be Ok and returns the value. Throws a StateError if the snapshot is not Ok.

Example:

ok(42).expect(); // 42
err<int>(Exception()).expect(); // throws StateError

Implementation

T expect() {
  if (!isOk()) {
    throw StateError('Value is not an Ok');
  }
  return data as T;
}