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 orElse to ApplicativeError #2243

Merged
merged 4 commits into from
May 6, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/applicativeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ final class ApplicativeErrorOps[F[_], E, A](val fa: F[A]) extends AnyVal {
def onError(pf: PartialFunction[E, F[Unit]])(implicit F: ApplicativeError[F, E]): F[A] =
F.onError(fa)(pf)

def or(other: F[A])(implicit F: ApplicativeError[F, E]): F[A] =
def orElse(other: => F[A])(implicit F: ApplicativeError[F, E]): F[A] =
F.handleErrorWith(fa)(_ => other)
}
8 changes: 4 additions & 4 deletions tests/src/test/scala/cats/tests/ApplicativeErrorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class ApplicativeErrorSuite extends CatsSuite {
failed.recoverWith { case _ => Some(7) } should === (Some(7))
}

test("or leaves unchanged a success") {
17.some or None should === (Some(17))
test("orElse leaves a success unchanged") {
17.some orElse None should === (Some(17))
Copy link
Contributor

Choose a reason for hiding this comment

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

this test is only testing the the Option.orElsemethod.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

paris_tuileries_garden_facepalm_statue

}

test("or transforms an error to the alternative") {
failed or Some(17) should === (Some(17))
test("orElse transforms an error to the alternative") {
failed orElse Some(17) should === (Some(17))
}
}