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

Delete unnecessary restriction on biFlatMap #2837

Merged
merged 4 commits into from
May 10, 2019
Merged
Changes from all commits
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
9 changes: 4 additions & 5 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final case class EitherT[F[_], A, B](value: F[Either[A, B]]) {
case Right(b) => F.pure(b)
}

def orElse[AA, BB >: B](default: => EitherT[F, AA, BB])(implicit F: Monad[F]): EitherT[F, AA, BB] =
def orElse[C, BB >: B](default: => EitherT[F, C, BB])(implicit F: Monad[F]): EitherT[F, C, BB] =
EitherT(F.flatMap(value) {
case Left(_) => default.value
case r @ Right(_) => F.pure(r.leftCast)
Expand Down Expand Up @@ -85,8 +85,7 @@ final case class EitherT[F[_], A, B](value: F[Either[A, B]]) {
applicativeG: Applicative[G]): G[EitherT[F, C, D]] =
applicativeG.map(traverseF.traverse(value)(axb => Bitraverse[Either].bitraverse(axb)(f, g)))(EitherT.apply)

def biflatMap[AA >: A, BB >: B](fa: A => EitherT[F, AA, BB],
fb: B => EitherT[F, AA, BB])(implicit F: FlatMap[F]): EitherT[F, AA, BB] =
def biflatMap[C, D](fa: A => EitherT[F, C, D], fb: B => EitherT[F, C, D])(implicit F: FlatMap[F]): EitherT[F, C, D] =
EitherT(F.flatMap(value) {
case Left(a) => fa(a).value
case Right(a) => fb(a).value
Expand Down Expand Up @@ -122,7 +121,7 @@ final case class EitherT[F[_], A, B](value: F[Either[A, B]]) {

def leftMap[C](f: A => C)(implicit F: Functor[F]): EitherT[F, C, B] = bimap(f, identity)

def leftFlatMap[BB >: B, D](f: A => EitherT[F, D, BB])(implicit F: Monad[F]): EitherT[F, D, BB] =
def leftFlatMap[BB >: B, C](f: A => EitherT[F, C, BB])(implicit F: Monad[F]): EitherT[F, C, BB] =
EitherT(F.flatMap(value) {
case Left(a) => f(a).value
case r @ Right(_) => F.pure(r.leftCast)
Expand Down Expand Up @@ -248,7 +247,7 @@ final case class EitherT[F[_], A, B](value: F[Either[A, B]]) {
* res0: EitherT[Option, NonEmptyList[Error], Int] = EitherT(Some(Left(NonEmptyList(error 1, error 2, error 3))))
* }}}
*/
def withValidated[AA, BB](f: Validated[A, B] => Validated[AA, BB])(implicit F: Functor[F]): EitherT[F, AA, BB] =
def withValidated[C, D](f: Validated[A, B] => Validated[C, D])(implicit F: Functor[F]): EitherT[F, C, D] =
EitherT(F.map(value)(either => f(either.toValidated).toEither))

def show(implicit show: Show[F[Either[A, B]]]): String = show.show(value)
Expand Down