Skip to content

Instantly share code, notes, and snippets.

@dkomanov
Created May 22, 2020 22:52
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/4a510341fb2c22bfc63b2ca044757eb0 to your computer and use it in GitHub Desktop.
Save dkomanov/4a510341fb2c22bfc63b2ca044757eb0 to your computer and use it in GitHub Desktop.
[writing-async-app-in-scala-part-1] recoverFilter
implicit class FutureExtensions[T](val future: Future[T]) extends AnyVal {
def recoverFilter(f: => T): Future[T] =
future.recover {
case _: NoSuchElementException | ControlException => f
}
def recoverFilterWith(f: => Future[T]): Future[T] =
future.recoverWith {
case _: NoSuchElementException | ControlException => f
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment