Skip to content

Instantly share code, notes, and snippets.

@malcolmgreaves
Created April 7, 2016 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malcolmgreaves/d06a7e01202a5792c7c9031b643ffd70 to your computer and use it in GitHub Desktop.
Save malcolmgreaves/d06a7e01202a5792c7c9031b643ffd70 to your computer and use it in GitHub Desktop.
Easily convert a Try[T] into a scalaz.\/[Throwable, T]
implicit class TryToDisjunction[T](private val x: Try[T]) extends AnyVal {
@inline def toOr: \/[Throwable, T] =
x match {
case Success(value) => \/-(value)
case Failure(e) => -\/(e)
}
}
@gregsilin
Copy link

Nice! Suggest wrapping the Failure catch clause with NonFatal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment