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 1 commit
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(s"division by zero: $dividend / 0")
Copy link
Contributor

@kailuowang kailuowang Dec 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/home/travis/build/typelevel/cats/core/src/main/scala/cats/ApplicativeError.scala:23: Variable dividend undefined in comment for method raiseError in trait ApplicativeError

[error] * | if (divisor === 0) F.raiseError(s"division by zero: $dividend / 0")

Scaladocs seems to be parsing $XXXX token, the easiest thing to do is probably to let it win and remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right I've dealt with this before. There's a trick to fix it, but the string interpolation isn't adding much to the example anyway so I'll just remove it.

* | 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: 6 / 0)
* }}}
*/
def raiseError[A](e: E): F[A]

Expand Down