This is a follow-up to my previous question.
I would like to write a non-recursive retry
function using the signature from the reply. Note that this implementation uses view
as a lazy sequence.
def withRetries[T](retries: Short)(fun: => T): Try[T] = {
(0 until retries).view.map(_ => Try(fun)).partition(_.isFailure) match {
case (a, b) if b.isEmpty => a.last
case (_, b) => b.head
}
}
Does it make sense ? How would you improve it ?