From 6d497eb196630f29edcb97aef55f3fc7bd9aaa39 Mon Sep 17 00:00:00 2001 From: Cody Allen Date: Wed, 20 Dec 2017 11:04:01 -0800 Subject: [PATCH] Add doctest example for ApplicativeError.raiseError (#2122) * Add doctest example for ApplicativeError.raiseError * Fix scaladoc interpretation issue in raiseError example --- .../main/scala/cats/ApplicativeError.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/main/scala/cats/ApplicativeError.scala b/core/src/main/scala/cats/ApplicativeError.scala index 7e2b9171b8..684ac7ace4 100644 --- a/core/src/main/scala/cats/ApplicativeError.scala +++ b/core/src/main/scala/cats/ApplicativeError.scala @@ -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]