Skip to content

Commit 09d689b

Browse files
authored
Merge pull request scala#5135 from soc/topic/biased-either
Right-bias Either
2 parents ea2f2bf + bd9654d commit 09d689b

File tree

5 files changed

+309
-94
lines changed

5 files changed

+309
-94
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BackendReporting.scala

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ final class BackendReportingImpl(val global: Global) extends BackendReporting {
2626
/**
2727
* Utilities for error reporting.
2828
*
29-
* Defines some tools to make error reporting with Either easier. Would be subsumed by a right-biased
30-
* Either in the standard library (or scalaz \/) (Validation is different, it accumulates multiple
31-
* errors).
29+
* Defines some utility methods to make error reporting with Either easier.
3230
*/
3331
object BackendReporting {
3432
def methodSignature(classInternalName: InternalName, name: String, desc: String) = {
@@ -42,19 +40,12 @@ object BackendReporting {
4240
def assertionError(message: String): Nothing = throw new AssertionError(message)
4341

4442
implicit class RightBiasedEither[A, B](val v: Either[A, B]) extends AnyVal {
45-
def map[C](f: B => C): Either[A, C] = v.right.map(f)
46-
def flatMap[C](f: B => Either[A, C]): Either[A, C] = v.right.flatMap(f)
4743
def withFilter(f: B => Boolean)(implicit empty: A): Either[A, B] = v match {
4844
case Left(_) => v
4945
case Right(e) => if (f(e)) v else Left(empty) // scalaz.\/ requires an implicit Monoid m to get m.empty
5046
}
51-
def foreach[U](f: B => U): Unit = v.right.foreach(f)
5247

53-
def getOrElse[C >: B](alt: => C): C = v.right.getOrElse(alt)
54-
55-
/**
56-
* Get the value, fail with an assertion if this is an error.
57-
*/
48+
/** Get the value, fail with an assertion if this is an error. */
5849
def get: B = {
5950
assert(v.isRight, v.left.get)
6051
v.right.get

0 commit comments

Comments
 (0)