summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/backend/jvm
diff options
context:
space:
mode:
authorStefan Zeiger <szeiger@novocode.com>2016-07-13 00:00:21 +0200
committerGitHub <noreply@github.com>2016-07-13 00:00:21 +0200
commit09d689b8f0ea185077e60d6cf22092dd10da1387 (patch)
tree3698a11154cb57260e18369b11241d6ea9f2f4b3 /src/compiler/scala/tools/nsc/backend/jvm
parentea2f2bf7d3b3e9be76527fb8f660b8b6babe8876 (diff)
parentbd9654d4a22bcccbd98d0f33699ece25f2c0904a (diff)
downloadscala-09d689b8f0ea185077e60d6cf22092dd10da1387.tar.gz
scala-09d689b8f0ea185077e60d6cf22092dd10da1387.tar.bz2
scala-09d689b8f0ea185077e60d6cf22092dd10da1387.zip
Merge pull request #5135 from soc/topic/biased-either
Right-bias Either
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend/jvm')
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BackendReporting.scala13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BackendReporting.scala b/src/compiler/scala/tools/nsc/backend/jvm/BackendReporting.scala
index 4ad4a95728..7b640ac54f 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BackendReporting.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BackendReporting.scala
@@ -26,9 +26,7 @@ final class BackendReportingImpl(val global: Global) extends BackendReporting {
/**
* Utilities for error reporting.
*
- * Defines some tools to make error reporting with Either easier. Would be subsumed by a right-biased
- * Either in the standard library (or scalaz \/) (Validation is different, it accumulates multiple
- * errors).
+ * Defines some utility methods to make error reporting with Either easier.
*/
object BackendReporting {
def methodSignature(classInternalName: InternalName, name: String, desc: String) = {
@@ -42,19 +40,12 @@ object BackendReporting {
def assertionError(message: String): Nothing = throw new AssertionError(message)
implicit class RightBiasedEither[A, B](val v: Either[A, B]) extends AnyVal {
- def map[C](f: B => C): Either[A, C] = v.right.map(f)
- def flatMap[C](f: B => Either[A, C]): Either[A, C] = v.right.flatMap(f)
def withFilter(f: B => Boolean)(implicit empty: A): Either[A, B] = v match {
case Left(_) => v
case Right(e) => if (f(e)) v else Left(empty) // scalaz.\/ requires an implicit Monoid m to get m.empty
}
- def foreach[U](f: B => U): Unit = v.right.foreach(f)
- def getOrElse[C >: B](alt: => C): C = v.right.getOrElse(alt)
-
- /**
- * Get the value, fail with an assertion if this is an error.
- */
+ /** Get the value, fail with an assertion if this is an error. */
def get: B = {
assert(v.isRight, v.left.get)
v.right.get