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 liftTo syntax to Validated #2293

Merged
merged 1 commit into from
Jun 13, 2018
Merged

Conversation

kailuowang
Copy link
Contributor

so that you can lift a Validated[E, A] to any F[A] that has an Applicative[F, E].

Note that I placed the syntax in a ValidatedOps value class mainly work around the variance requirement. (If the method is inside Validated you wouldn't be able to use E and A in invariant/contravariant position, so you would have to introduce an EE >: E and AA >: A but that requires extra type parameters to be passed in, which beat the purpose of this thing which is mostly ergonomic.

x match {
case Right(a) => pure(a)
case Left(e) => raiseError(e)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

replace fold to optimize performance ( this way there is no need to create anonymous functions, which take a toll. )

@kailuowang kailuowang changed the title added liftTo syntax to validated added liftTo syntax to Validated Jun 12, 2018
@codecov-io
Copy link

codecov-io commented Jun 12, 2018

Codecov Report

Merging #2293 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2293      +/-   ##
==========================================
+ Coverage   95.01%   95.03%   +0.02%     
==========================================
  Files         337      337              
  Lines        5835     5840       +5     
  Branches      216      222       +6     
==========================================
+ Hits         5544     5550       +6     
+ Misses        291      290       -1
Impacted Files Coverage Δ
core/src/main/scala/cats/ApplicativeError.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/syntax/validated.scala 100% <100%> (+20%) ⬆️
.../src/main/scala/cats/syntax/applicativeError.scala 100% <100%> (ø) ⬆️

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 1d7ee78...49c5d9f. Read the comment docs.

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.

Looks good to me 👍

I wonder though, if we have opaque types in the future and we want to make Validated a newtype over Either (for performance benefits when converting between the two), if this will be redundant. Though of course that's fairly far into the future :)

Copy link
Contributor

@johnynek johnynek left a comment

Choose a reason for hiding this comment

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

This is nice!

@johnynek johnynek merged commit c712a65 into typelevel:master Jun 13, 2018
@kailuowang kailuowang added this to the 1.2 milestone Jul 23, 2018
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.

4 participants