Fred Friis
06/16/2020, 8:32 AMreturn entries
.asSequence() //turning it into a sequence first enables short circuiting on first encountered failure
.map { callDownstreamForEntry(it) } //make the call to downstream
.firstOption { outcome -> //find the first failure using the below filter
outcome
.fold({
true //we got an error calling downstream - failure found - short circuit
}, {
it.not() //we got a false from downstream - failure found - short circuit
})
}.getOrElse { true.right() } //if we reach here there were no errors calling downstream and no false
//from downstream, so return success