-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Recover Kleisli from F[_] errors #1601
Conversation
I might missed something but the |
@kailuowang you are right. I rewrote it like this: def recover[E](pf: PartialFunction[E, B])(implicit aek: ApplicativeError[Kleisli[F, A, ?], E]): Kleisli[F, A, B] =
aek.recover[B](this)(pf) That should do it. I'll fix the other two. |
I agree with @kailuowang. You get You might need to use a Scala version which supports Merging #1583 will definitely help in this case as well. |
Codecov Report
@@ Coverage Diff @@
## master #1601 +/- ##
=========================================
+ Coverage 93.09% 93.1% +<.01%
=========================================
Files 250 250
Lines 3983 3986 +3
Branches 130 136 +6
=========================================
+ Hits 3708 3711 +3
Misses 275 275
Continue to review full report at Codecov.
|
@kailuowang @peterneyens made the changes, didn't have problems running those tests. Just had to add the implicit instances for Kleisli with either and Kleisli with validated. |
@leandrob13 what we are saying is that the methods you added are redundant, they are already available through |
@kailuowang I just thought that they could be convenient. If you would want to recover a Kleisli you would have to invoke: ApplicativeError[Kleisli[Either[String, ?], Int, ?], String].recover(k) { ... } Am I right? I just thought it would be useful to do add a function that does this directly on Kleisli. k.recover { ... } Right now I am setting up the test for a use case that may have issues with the partial unification, I will try the plugin you suggest. |
@leandrob13, you don't have to write val k = Kleisli((i:Int) => if(i == 0) Left(1) else Right("big") )
val res13 = k.recover{ case 1 => "haha" }
res13.run(3)
// res14: Either[Int, String] = Right("big")
res13.run(0)
// res16: Either[Int, String] = Right("haha") For this to compile, you need partial-unification enabled. But usually the methods on typeclasses are "injected" directly onto the instance through the typeclass's syntax implicit conversion. |
@kailuowang I had no idea you could do that. Thanks, this is going to be of great help! I will close the PR. |
Added functions for recovering from errors from F[_].
The functions recover, recoverWith and recoverWithF need an ApplicativeError instance for F[_].