tryAsResultSync<T> function

Result<T> tryAsResultSync<T>(
  1. T? f()
)

Calls Function f Returns Err(...) if call result is null or function call throws error. Otherwise seturns Ok(...).

Implementation

Result<T> tryAsResultSync<T>(T? Function() f) {
  try {
    var callResult = f();
    return callResult == null
        ? Err<T>(StateError('function returned null'))
        : Ok(callResult);
  } catch (e) {
    return Err(StateError('$e'));
  }
}