bjonnh
06/24/2020, 8:10 PMfun <A> IO<Nothing, A>.retry(shouldRetry: (count: Int, error: Throwable) -> Boolean): IO<Throwable, A> =
handleErrorWith { withRetry(it, 1, shouldRetry) }
fun <A> IO<Throwable, A>.withRetry(err: Throwable, count: Int, shouldRetry: (count: Int, error: Throwable) -> Boolean): IO<Throwable, A> =
if (!shouldRetry(count, err)) IO.raiseError(err)
else handleErrorWith {
withRetry(it, count + 1, shouldRetry)
}