tryEitherAsync<T> function

AsyncResult<T> tryEitherAsync<T>(
  1. FutureOr<T> block(
    1. BindEither bind
    )
)

Implementation

AsyncResult<T> tryEitherAsync<T>(
  FutureOr<T> Function(BindEither bind) block,
) async {
  A bind<A>(Result<A> either) => either.fold((e) => throw e, identity);

  try {
    return Either.right(await block(bind));
  } on Exception catch (e) {
    return Either.left(e);
  }
}