-
Notifications
You must be signed in to change notification settings - Fork 437
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
Try docs #458
Try docs #458
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahdezma excellent and great work! Let's remove the exception throwing example before we merge and add an example that uses Try.monadError().bindingE
where an exception is thrown by a call in the comprehension and you can see that it automatically lifts the exception to the context of Try
thanks to bindingE
## Try | ||
## Try | ||
|
||
Kategory has a lots of different types of error handling and reporting, which can make it difficult to decide which one is best for your situation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to http://kategory.io/docs/patterns/error_handling/ for disambiguation on when to use each strategy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw AuthorizationException() | ||
} | ||
|
||
fun getLotteryNumbersFromCloud(): List<User> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would getUsers
be a more appropriate name here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```kotlin:ank | ||
lotteryTry.recover { | ||
if (it is NoConnectionException) emptyList() | ||
else throw it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not a good example because it promotes exception throwing. We should instead here return another Try
or use recoverWith
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or coalesce to a List regardless of the exception type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
``` | ||
|
||
Or if you have another different computation that can also fail, you can use `recoverWith` to recover from an error (as you do with `recover`, but in this case, returning a new `Try`): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual example we need recoverWith
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand the request here :)
|
||
[`Functor`]({{ '/docs/typeclasses/functor/' | relative_url }}) | ||
|
||
Transforming the value, if the computation is a success |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor, but for consistancy this heading, Computing over independent values
, andComputing over dependent values ignoring failure
should end in a colon. e.g. Transforming the value, if the computation is a success:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2574a1a Thanks :)
## Try | ||
## Try | ||
|
||
Kategory has a [lots of different types of error handling and reporting](http://kategory.io/docs/patterns/error_handling/), which can make it difficult to decide which one is best for your situation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace: which can make it difficult to decide which one is best for your situation
For: which allows you to choose the best strategy for your situation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work, added a final comment and this is ready to go once addressed!
|
||
Computing over dependent values ignoring failure: | ||
|
||
```kotlin:ank |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These next 2 blocks will never complete in ank
because the interpreter isn't ready for coroutines yet. Please revert them to regular kotlin
blocks and hardcode the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
Computing over dependent values that are automatically lifted to the context of `Try`: | ||
|
||
```kotlin:ank |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, binding is not possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
The following example represents the typical case when consuming Java code, where domain errors are represented with exceptions. | ||
|
||
```kotlin:ank |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add silent to this block to avoid getting a blank return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI will never complete until the comprehensions are removed. Sad, but we'll add them later.
No need to actually remove the comprehensions just remove |
Codecov Report
@@ Coverage Diff @@
## master #458 +/- ##
=========================================
Coverage ? 35.98%
Complexity ? 331
=========================================
Files ? 184
Lines ? 5019
Branches ? 547
=========================================
Hits ? 1806
Misses ? 3052
Partials ? 161
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the power of grayskull, let's merge!
No description provided.