Skip to content

Instantly share code, notes, and snippets.

def myBusinessStuff(...) = {
// Implementations and explicit names
val action1 = ???
val action2 = ???
val action3 = ???
// What business people should almost be able to understand
for {
_ <- action1
@mmenestret
mmenestret / ShortCircuit.scala
Created January 30, 2020 16:16
Short circuit List of Future based on predicate
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)
}
}