Skip to content

Commit

Permalink
Delete unnecessary restriction on biFlatMap (#2837)
Browse files Browse the repository at this point in the history
* delete unnecessary restriction on biFlatMap

* formatting after prePR

* make types consistent

* restore type names for related types
  • Loading branch information
AdrianRaFo authored and kailuowang committed May 10, 2019
1 parent 4894122 commit 912a14a
Showing 1 changed file with 4 additions and 5 deletions.
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

0 comments on commit 912a14a

Please sign in to comment.