Skip to content

Instantly share code, notes, and snippets.

@dkomanov
Created May 22, 2020 22:18
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/13384a69194098916308a38cdc8ead8a to your computer and use it in GitHub Desktop.
Save dkomanov/13384a69194098916308a38cdc8ead8a to your computer and use it in GitHub Desktop.
[writing-async-app-in-scala-part-1] for-comprehensions 6
implicit class FutureExtensions[T](val future: Future[T]) extends AnyVal {
def filterOrFail(f: T => Boolean, e: => Throwable): Future[T] =
future.flatMap(value => if (f(value)) Future.successful(value) else Future.failed(e))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment