Skip to content

Commit

Permalink
Rename Eval.raise to Eval.raiseError (#1634)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandru authored and kailuowang committed May 18, 2017
1 parent 69793a9 commit 2fd530b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions core/src/main/scala/cats/Eval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ sealed abstract class Eval[+A] extends Serializable { self =>
* `.handleErrorWith`.
*
* The `recovery` method can re-raise exceptions (if necessary)
* using the `Eval.raise` method, or via `throw` directly.
* using the `Eval.raiseError` method, or via `throw` directly.
* Exceptions "at-rest" are not represented with `Eval`, your only
* options for catching and dealing with exceptions are this method,
* or wrapping your `.value` calls with something like `Try()`.
Expand All @@ -142,7 +142,7 @@ sealed abstract class Eval[+A] extends Serializable { self =>
* capabilities of `Eval`.
*/
final def recoverWith[A1 >: A](f: PartialFunction[Throwable, Eval[A1]]): Eval[A1] =
handleErrorWith(t => if (f.isDefinedAt(t)) f(t) else Eval.raise(t))
handleErrorWith(e => if (f.isDefinedAt(e)) f(e) else Eval.raiseError(e))
}


Expand Down Expand Up @@ -248,8 +248,8 @@ object Eval extends EvalInstances {
* This method can be paired with the `.recoverWith` method to
* encode exception handling within an `Eval` context.
*/
def raise(t: Throwable): Eval[Nothing] =
Eval.defer(throw t)
def raiseError[A](e: Throwable): Eval[A] =
Eval.defer(throw e)

/**
* Static Eval instance for common value `Unit`.
Expand Down Expand Up @@ -388,7 +388,7 @@ private[cats] trait EvalInstances extends EvalInstances0 {
def handleErrorWith[A](fa: Eval[A])(f: Throwable => Eval[A]): Eval[A] =
fa.handleErrorWith(f)
def raiseError[A](e: Throwable): Eval[A] =
Eval.raise(e)
Eval.raiseError(e)
}

implicit val catsReducibleForEval: Reducible[Eval] =
Expand Down
8 changes: 4 additions & 4 deletions tests/src/test/scala/cats/tests/EvalTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ class EvalTests extends CatsSuite {
loop(100000, Now(6)).value should === (6)
}

test("Eval.raise(t).handleErrorWith(f) = f(t)") {
forAll { (t: Throwable, f: Throwable => Eval[Int]) =>
Eval.raise(t).handleErrorWith(f) should === (f(t))
test("Eval.raiseError(e).handleErrorWith(f) = f(e)") {
forAll { (e: Throwable, f: Throwable => Eval[Int]) =>
Eval.raiseError(e).handleErrorWith(f) should === (f(e))
}
}

Expand All @@ -113,7 +113,7 @@ class EvalTests extends CatsSuite {

// test with a partial recovery function
val x2 = Try(e.recoverWith(p).value)
val y2 = Try(e.handleErrorWith(t => if (p.isDefinedAt(t)) p(t) else Eval.raise(t)).value)
val y2 = Try(e.handleErrorWith(e => if (p.isDefinedAt(e)) p(e) else Eval.raiseError(e)).value)
x2 should === (y2)

// ensure that this works if we throw directly
Expand Down

0 comments on commit 2fd530b

Please sign in to comment.