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

Adding biSemiFlatMap to EitherT #2269

Closed
ericaovo opened this issue May 24, 2018 · 0 comments
Closed

Adding biSemiFlatMap to EitherT #2269

ericaovo opened this issue May 24, 2018 · 0 comments

Comments

@ericaovo
Copy link
Contributor

Looking into the methods available on an EitherT instance I came across the need of having something like the following:

def biSemiflatMap[C, D](fa: A => F[C], fb: B => F[D]): EitherT[F, C, D] =
  eitherT.leftSemiflatMap(fa).semiflatMap(fb)

Here's an example:

import cats.data._, cats.implicits._, cats.Monad

val eitherT: EitherT[List, String, Int] = EitherT(List(Left("abc"), Right(123)))

implicit class EitherTOps[F[_]: Monad, A, B](val eitherT: EitherT[F, A, B]) {
  def biSemiflatMap[C, D](fa: A => F[C], fb: B => F[D]): EitherT[F, C, D] =
    eitherT.leftSemiflatMap(fa).semiflatMap(fb)
}

eitherT.biSemiflatMap(string => List(string.length), int => List(int.toFloat))
// res: cats.data.EitherT[List,Int,Float] = EitherT(List(Left(3), Right(123.0)))

Happy to open a PR if it sounds reasonable.

kailuowang pushed a commit that referenced this issue Jun 11, 2018
* Adding biSemiflatMap to EitherT

* Expanding leftSemiflatMap and semiflatMap

* Added documentation

* Added EitherT types for 2.10 and 2.11
eli-jordan pushed a commit to eli-jordan/cats that referenced this issue Jun 16, 2018
* Adding biSemiflatMap to EitherT

* Expanding leftSemiflatMap and semiflatMap

* Added documentation

* Added EitherT types for 2.10 and 2.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant