Created
May 22, 2020 22:18
-
-
Save dkomanov/13384a69194098916308a38cdc8ead8a to your computer and use it in GitHub Desktop.
[writing-async-app-in-scala-part-1] for-comprehensions 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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