Either<L, R>.tryCatch constructor

Either<L, R>.tryCatch({
  1. required R execute(),
  2. required L onError(
    1. Object o,
    2. StackTrace s
    ),
})

Implementation

factory Either.tryCatch({
  required R Function() execute,
  required L Function(Object o, StackTrace s) onError,
}) {
  try {
    return Right(execute());
  } catch (e, s) {
    return Left(onError(e, s));
  }
}