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

added leftT and improved existing lift API for EitherT #1614

Merged
merged 2 commits into from
Apr 24, 2017

Conversation

kailuowang
Copy link
Contributor

using PartiallyApplied to improve the API
added a leftT and rightT alias

@codecov-io
Copy link

codecov-io commented Apr 18, 2017

Codecov Report

Merging #1614 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1614      +/-   ##
==========================================
+ Coverage   93.08%   93.12%   +0.04%     
==========================================
  Files         250      250              
  Lines        3989     3999      +10     
  Branches      136      135       -1     
==========================================
+ Hits         3713     3724      +11     
+ Misses        276      275       -1
Impacted Files Coverage Δ
core/src/main/scala/cats/data/EitherT.scala 96.42% <100%> (+0.23%) ⬆️
core/src/main/scala/cats/data/package.scala 83.33% <0%> (ø) ⬆️
...rc/main/scala/cats/laws/discipline/Arbitrary.scala 90.32% <0%> (+0.49%) ⬆️
core/src/main/scala/cats/data/Kleisli.scala 93.82% <0%> (+1.23%) ⬆️

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 b78758c...5e67748. Read the comment docs.

@kailuowang kailuowang changed the title added leftT and improved existing creation API for EitherT added leftT and improved existing lift API for EitherT Apr 18, 2017
@diego-alvarez-hs
Copy link

Thank you for this @kailuowang


final def right[F[_], A, B](fb: F[B])(implicit F: Functor[F]): EitherT[F, A, B] = EitherT(F.map(fb)(Either.right))
final class LeftPartiallyApplied[B] private[EitherTFunctions] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious. Is Scalaz's trick here (add a dummy parameter to this class to make it an AnyVal; see here) necessary to make this zero-cost?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems a nice trick. Do we want to use it here first in this PR, or create another PR applying the pattern globally?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm okay with another PR to apply it globally.

Copy link
Contributor

@edmundnoble edmundnoble left a comment

Choose a reason for hiding this comment

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

LGTM.

@kailuowang kailuowang added this to the 1.0.0-MF milestone Apr 20, 2017
* res1: EitherT[List, String, Int] = EitherT(List(Right(42)))
* }}}
*/
final def fromOptionF[F[_], E, A](fopt: F[Option[A]], ifNone: => E)(implicit F: Functor[F]): EitherT[F, E, A] =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just wondering, is this better than OptionT(fopt).toRight(ifNone) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't know about the OptionT.toRight, Looks like this one has slightly less function calls and an allocation to OptionT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peterneyens anything else in this PR?

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