getValueSafely<T> function

Either<Object, T?> getValueSafely<T>(
  1. T? getValueAction()
)

run getValueAction with try-catch return the result of getValueAction if no exception occurs, otherwise return null instead.

Implementation

Either<Object, T?> getValueSafely<T>(T? Function() getValueAction) {
  try {
    final value =  getValueAction.call();
    return Right(value);
  } catch(e, _) {
    return Left(e);
  }
}