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

Rename Eval.raise to Eval.raiseError #1634

Merged
merged 1 commit into from
May 18, 2017
Merged
Show file tree
Hide file tree
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
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