Skip to content

Instantly share code, notes, and snippets.

@MariiaRa
MariiaRa / left.scala
Created February 12, 2019 10:54 — forked from HerringtonDarkholme/left.scala
foldLeft and foldRight
def retry(noTimes: Int)(block: Future[T]): Future[T] = {
val ns: Iterator[Int] = (1 to noTimes).iterator
val attempts: Iterator[Future[T]] = ns.map(_⇒ ()block)
val failed = Future.failed(new Exception)
attempts.foldLeft(failed)
((a,block) a recoverWith { block() })
}
retry(3) { block }
= unfolds to