aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/common/compat/EitherOps.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/xyz/driver/common/compat/EitherOps.scala')
-rw-r--r--src/main/scala/xyz/driver/common/compat/EitherOps.scala12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/common/compat/EitherOps.scala b/src/main/scala/xyz/driver/common/compat/EitherOps.scala
new file mode 100644
index 0000000..b3b45e6
--- /dev/null
+++ b/src/main/scala/xyz/driver/common/compat/EitherOps.scala
@@ -0,0 +1,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)
+ }
+
+}