Skip to content

Commit

Permalink
Reword the description of error syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Gómez committed May 21, 2016
1 parent dbbc9ac commit e661239
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docs/src/tut/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,17 @@ val result: Int = Fetch.run[Eval](fetchPure).value
### error

Errors can also be lifted to the Fetch monad, in this case with `Fetch#error`. Note that interpreting
an errorful fetch to `Eval` will throw the exception so we won't do that:
an errorful fetch to `Eval` won't throw the exception unless we access the value with the `.value` method.

A safer way to deal with errors is to use MonadError's `attempt` to turn the exception into a `Xor.Left` value:

```tut:book
val ME = implicitly[MonadError[Eval, Throwable]]
```tut:silent
val fetchFail: Fetch[Int] = Fetch.error(new Exception("Something went terribly wrong"))
val result: Eval[Int] = fetchFail.runA[Eval]
val safeResult: Eval[Throwable Xor Int] = ME.attempt(result)
val finalValue: Throwable Xor Int = safeResult.value
```

### join
Expand Down

0 comments on commit e661239

Please sign in to comment.