Last active
August 29, 2015 14:00
-
-
Save manjuraj/11026922 to your computer and use it in GitHub Desktop.
Try - Either
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.{Try, Success, Failure} | |
implicit class EitherOps[L <: Throwable, R](val e: Either[L, R]) extends AnyVal { | |
def toTry: Try[R] = e.fold(Failure(_), Success(_)) | |
} | |
implicit class TryOps[T](val t: Try[T]) extends AnyVal { | |
def toEither: Either[Throwable, T] = t match { | |
case Failure(e) => Left(e) | |
case Success(v) => Right(v) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment