doEither<L, R> function

Either<L, R> doEither<L, R>(
  1. R f(
    1. A <A>(
      1. Either<L, A>
      )
    )
)

Implementation

Either<L, R> doEither<L, R>(
  R Function(
    A Function<A>(Either<L, A>),
  ) f,
) {
  try {
    return Right(
      f(
        <A>(either) => switch (either) {
          Right(value: final value) => value,
          Left(value: final value) => throw _EvalException(value)
        },
      ),
    );
  } on _EvalException<L> catch (e) {
    return Left(e.value);
  }
}