Skip to content

Instantly share code, notes, and snippets.

@byF
Created October 1, 2020 22:37
Show Gist options
  • Save byF/ff46914fab68ee1d98c5dcc384171906 to your computer and use it in GitHub Desktop.
Save byF/ff46914fab68ee1d98c5dcc384171906 to your computer and use it in GitHub Desktop.
Oh Scala, I wish Try's getOrElse could access the throwable in the "else" block by default
implicit class RichTry[T](val poorTry: Try[T]) extends AnyVal {
def getOrElseT[U >: T](default: Throwable => U): U = poorTry.fold(default, x => x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment