Skip to content

Commit

Permalink
Add doctest example for ApplicativeError.raiseError (#2122)
Browse files Browse the repository at this point in the history
* Add doctest example for ApplicativeError.raiseError

* Fix scaladoc interpretation issue in raiseError example
  • Loading branch information
ceedubs authored and kailuowang committed Dec 20, 2017
1 parent 5051b36 commit 6d497eb
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit 6d497eb

Please sign in to comment.