Skip to content

Instantly share code, notes, and snippets.

@dkomanov
Last active May 31, 2020 11:38
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 dkomanov/1271d7f13aad9dc9142fcb2eaff173e5 to your computer and use it in GitHub Desktop.
Save dkomanov/1271d7f13aad9dc9142fcb2eaff173e5 to your computer and use it in GitHub Desktop.
[writing-async-app-in-scala-part-1] option 1
implicit class FutureOfOptionExtensions[T](val v: Future[Option[T]]) extends AnyVal {
def orFail(e: => Throwable): Future[T] =
v.flatMap(_.fold[Future[T]](Future.failed(e), Future.successful)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment