rawSync method

Sync<Object> rawSync()

Safely reduces any Outcome chain to a single Sync.

It provides a direct way to get a raw synchronous value while collapsing all failure, empty, or asynchronous states into an Err.

Example

final success = Ok(Some(42)).rawSync();      // Contains Ok(42)
final empty = Ok(None<int>()).rawSync();   // Contains Err(...)
final failed = Err('fail').rawSync();      // Contains Err('fail')
final isAsync = Async(() => 1).rawSync(); // Contains Err(...)

Implementation

Sync rawSync() {
  return Sync(() {
    // ignore: no_futures
    final value = raw(
      onErr: (err) => err,
      onNone: () => Err('The Outcome resolved to a None (empty) state!'),
    );
    if (value is Future) {
      throw Err(
        'The Outcome contains an asynchronous value! Use rawAsync instead.',
      );
    }
    if (value is Err) {
      throw value;
    }
    return value;
  });
}