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

Try docs #458

Merged
merged 19 commits into from
Nov 22, 2017
Merged

Try docs #458

merged 19 commits into from
Nov 22, 2017

Conversation

alejandrohdezma
Copy link
Contributor

No description provided.

Copy link
Member

@raulraja raulraja left a 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.
Copy link
Member

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

Copy link
Contributor Author

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> {
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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`):
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Contributor

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:

Copy link
Contributor Author

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.
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@raulraja raulraja left a 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
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@pakoito pakoito left a 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.

@raulraja
Copy link
Member

No need to actually remove the comprehensions just remove :ank but we want those examples in the docs even at the risk of not properly type checking. We can create also ank:compile so that it does not use the script engine to eval and just the kotlinc embedded compiler that is already available in the classpath.

@codecov-io
Copy link

codecov-io commented Nov 22, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@1ae26be). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #458   +/-   ##
=========================================
  Coverage          ?   35.98%           
  Complexity        ?      331           
=========================================
  Files             ?      184           
  Lines             ?     5019           
  Branches          ?      547           
=========================================
  Hits              ?     1806           
  Misses            ?     3052           
  Partials          ?      161
Impacted Files Coverage Δ Complexity Δ
kategory-core/src/main/kotlin/kategory/data/Try.kt 20% <100%> (ø) 5 <0> (?)

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 1ae26be...9facecc. Read the comment docs.

Copy link
Member

@pakoito pakoito left a 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!

@pakoito pakoito merged commit ac9455c into arrow-kt:master Nov 22, 2017
@raulraja
Copy link
Member

#472

@nomisRev nomisRev mentioned this pull request Nov 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants