aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/common/compat/EitherOps.scala
blob: b3b45e6c15c97ce69fa5f80b94323814849b35db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
package xyz.driver.common.compat

final class EitherOps[A, B](val self: Either[A, B]) extends AnyVal {

  def map[B2](f: B => B2): Either[A, B2] = flatMap { x => Right(f(x)) }

  def flatMap[B2](f: B => Either[A, B2]): Either[A, B2] = self match {
    case Left(x) => Left(x)
    case Right(x) => f(x)
  }

}