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) #2274

Merged
merged 4 commits into from
Jun 11, 2018

Conversation

ericaovo
Copy link
Contributor

@ericaovo ericaovo commented Jun 1, 2018

Addresses #2269.

@codecov-io
Copy link

codecov-io commented Jun 1, 2018

Codecov Report

Merging #2274 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2274      +/-   ##
==========================================
+ Coverage   94.97%   94.97%   +<.01%     
==========================================
  Files         337      337              
  Lines        5832     5835       +3     
  Branches      217      206      -11     
==========================================
+ Hits         5539     5542       +3     
  Misses        293      293
Impacted Files Coverage Δ
core/src/main/scala/cats/data/EitherT.scala 97.7% <100%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3993dba...7015a82. Read the comment docs.

@@ -120,6 +120,9 @@ final case class EitherT[F[_], A, B](value: F[Either[A, B]]) {
case r@Right(_) => F.pure(r.leftCast)
})

def biSemiflatMap[C, D](fa: A => F[C], fb: B => F[D])(implicit F: Monad[F]): EitherT[F, C, D] =
leftSemiflatMap(fa).semiflatMap(fb)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to implement this in a single walk over F?

If F is e.g. List, this would traverse the list twice, and we should probably not do that ;)

Other than that, I think it's worth mentioning this PR to one of the maintainers, since there hasn't been any activity from them on this or the original issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point @kubukoz , so I would refactor it to be:

def biSemiflatMap[C, D](fa: A => F[C], fb: B => F[D])(implicit F: Monad[F]): EitherT[F, C, D] =
    EitherT(F.flatMap(value) {
      case Left(a) => F.map(fa(a)) { c => Left(c) }
      case Right(b) => F.map(fb(b)) { d => Right(d) }
    })

In this case it will flatMap and map it once, instead of flatMap it twice.

@ericaovo
Copy link
Contributor Author

ericaovo commented Jun 7, 2018

@kailuowang would you mind reviewing this please?

kailuowang
kailuowang previously approved these changes Jun 7, 2018
Copy link
Contributor

@kailuowang kailuowang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry about the delay

LukaJCB
LukaJCB previously approved these changes Jun 8, 2018
Copy link
Member

@LukaJCB LukaJCB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

There seems to be some issues with the 2.10 and 2.11 builds though, might have to add an explicit type parameter :)

@ericaovo
Copy link
Contributor Author

ericaovo commented Jun 8, 2018

Sorry about that, I just had the time to fix it now, thank you! :) Would you mind having another look @LukaJCB @kailuowang ? I've automatically dismissed your approval when I pushed :|

@kailuowang kailuowang merged commit bfbf021 into typelevel:master Jun 11, 2018
@kailuowang kailuowang added this to the 1.2 milestone Jun 11, 2018
eli-jordan pushed a commit to eli-jordan/cats that referenced this pull request 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants