fromThrowable<T, E> static method

Result<T, E> fromThrowable<T, E>(
  1. T fn(), {
  2. E errorFn(
    1. Object?
    )?,
})

TODO: Need to figure out how to wrap the function instead

Implementation

static Result<T, E> fromThrowable<T, E>(T Function() fn,
    {E Function(Object?)? errorFn}) {
  try {
    return ok(fn());
  } catch (e) {
    return err(errorFn != null ? errorFn(e) : e as E);
  }
}