Skip to content

Commit

Permalink
feat(80): Added documentation in the README file
Browse files Browse the repository at this point in the history
  • Loading branch information
rcardin committed Sep 23, 2024
1 parent 4bf29e2 commit 6b20a68
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cats-raise4s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,23 @@ In general, the integration lets you use the _Cats_ type classes with the _Raise

```scala 3
CatsRaise.validated { raise("error") } should be(Validated. invalid("error"))
```
```

- Use the `RaiseMonadError[E]` to integrate with your existing code that uses `MonadError[E]`.

```scala 3
import in.rcard.raise4s.cats.instances.raise.given

private def attemptDivideApplicativeError[F[_]](x: Int, y: Int)(implicit
ae: ApplicativeError[F, String]
): F[Int] = {
if (y == 0) ae.raiseError("divisor is zero")
else {
ae.pure(x / y)
}
}

type OrError[A] = Raise[String] ?=> A
val actual: OrError[Int] = attemptDivideApplicativeError[OrError](30, 0)
Raise.run { actual } shouldBe "divisor is zero"
```

0 comments on commit 6b20a68

Please sign in to comment.