sequenceTuple2<L, R1, R2> function

TaskEither<L, (R1, R2)> sequenceTuple2<L, R1, R2>(
  1. TaskEither<L, R1> te1,
  2. TaskEither<L, R2> te2
)

Implementation

TaskEither<L, (R1, R2)> sequenceTuple2<L, R1, R2>(
  TaskEither<L, R1> te1,
  TaskEither<L, R2> te2,
) =>
    () async {
      try {
        final result = await Future.wait(
          [
            () async {
              final res1 = await te1();
              switch (res1) {
                case E.Right(value: final value):
                  return value;
                case E.Left(value: final value):
                  throw _FailFastException(value);
              }
            }(),
            () async {
              final res2 = await te2();
              switch (res2) {
                case E.Right(value: final value):
                  return value;
                case E.Left(value: final value):
                  throw _FailFastException(value);
              }
            }(),
          ],
          eagerError: true,
        );

        return E.Right(
          (
            result[0] as R1,
            result[1] as R2,
          ),
        );
      } on _FailFastException<L> catch (e) {
        return E.Left(e.value);
      }
    };