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

Add doctest example for ApplicativeError.raiseError #2122

Merged
merged 2 commits into from
Dec 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions core/src/main/scala/cats/ApplicativeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,27 @@ import scala.util.control.NonFatal
* This type class allows one to abstract over error-handling applicatives.
*/
trait ApplicativeError[F[_], E] extends Applicative[F] {

/**
* Lift an error into the `F` context.
*
* Example:
* {{{
* scala> import cats.implicits._
*
* // integer-rounded division
* scala> def divide[F[_]](dividend: Int, divisor: Int)(implicit F: ApplicativeError[F, String]): F[Int] =
* | if (divisor === 0) F.raiseError("division by zero")
* | else F.pure(dividend / divisor)
*
* scala> type ErrorOr[A] = Either[String, A]
*
* scala> divide[ErrorOr](6, 3)
* res0: ErrorOr[Int] = Right(2)
*
* scala> divide[ErrorOr](6, 0)
* res1: ErrorOr[Int] = Left(division by zero)
* }}}
*/
def raiseError[A](e: E): F[A]

Expand Down