Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed and replaced inconsistent Parallel derivation for EitherT #3777

Merged
merged 3 commits into from
Feb 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ abstract private[data] class EitherTInstances extends EitherTInstances1 {
EitherT(F.defer(fa.value))
}

implicit def catsDataParallelForEitherTWithParallelEffect[M[_], E: Semigroup](implicit
private[cats] def catsDataParallelForEitherTWithParallelEffect[M[_], E: Semigroup](implicit
P: Parallel[M]
): Parallel.Aux[EitherT[M, E, *], Nested[P.F, Validated[E, *], *]] =
new Parallel[EitherT[M, E, *]] {
Expand Down Expand Up @@ -956,6 +956,37 @@ abstract private[data] class EitherTInstances extends EitherTInstances1 {
}
}
}

implicit def catsDataParallelForEitherTWithParallelEffect2[M[_], E](implicit
P: Parallel[M]
): Parallel.Aux[EitherT[M, E, *], Nested[P.F, Either[E, *], *]] =
new Parallel[EitherT[M, E, *]] {
type F[x] = Nested[P.F, Either[E, *], x]

implicit val monadM: Monad[M] = P.monad
implicit val monadEither: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither

def applicative: Applicative[Nested[P.F, Either[E, *], *]] =
cats.data.Nested.catsDataApplicativeForNested(P.applicative, implicitly)

def monad: Monad[EitherT[M, E, *]] = cats.data.EitherT.catsDataMonadErrorForEitherT

def sequential: Nested[P.F, Either[E, *], *] ~> EitherT[M, E, *] =
new (Nested[P.F, Either[E, *], *] ~> EitherT[M, E, *]) {
def apply[A](nested: Nested[P.F, Either[E, *], A]): EitherT[M, E, A] = {
val mva = P.sequential(nested.value)
EitherT(Functor[M].map(mva)(x => x))
}
}

def parallel: EitherT[M, E, *] ~> Nested[P.F, Either[E, *], *] =
new (EitherT[M, E, *] ~> Nested[P.F, Either[E, *], *]) {
def apply[A](eitherT: EitherT[M, E, A]): Nested[P.F, Either[E, *], A] = {
val fea = P.parallel(eitherT.value)
Nested(P.applicative.map(fea)(x => x))
}
}
}
}

abstract private[data] class EitherTInstances1 extends EitherTInstances2 {
Expand Down