Skip to content

Instantly share code, notes, and snippets.

@manjuraj
Last active August 29, 2015 14:00
Show Gist options
  • Save manjuraj/11026922 to your computer and use it in GitHub Desktop.
Save manjuraj/11026922 to your computer and use it in GitHub Desktop.
Try - Either
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