Created
January 30, 2020 16:16
-
-
Save mmenestret/9b6aa45c0c94c9e82ecbcc922f3ff9f9 to your computer and use it in GitHub Desktop.
Short circuit List of Future based on predicate
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
def shortCircuitFutureList[A](fs: List[() => Future[A]], cond: A => Boolean)( | |
implicit executionContext: ExecutionContext): Future[A] = fs match { | |
case tail :: Nil => tail() | |
case head :: _ => | |
head() | |
.filter(cond) | |
.recoverWith { | |
case _ => shortCircuitFutureList(fs.tail, cond) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment