upstream -> upstream.retryWhen { cause, attempt -> println("cause: ${cause.javaClass.canonicalName}, attempt: $attempt") cause is NetworkException && attempt < 2 } } runBlocking { val f = flow<String> { throw NetworkException() } val f2 = flow<String> { throw InternalException() } try { f.let(retryConverter()).collect { value -> println(value) } } catch (e: NetworkException) { println("retried over 3 times.") } try { f2.let(retryConverter()).collect { value -> println(value) } } catch (e: InternalException) { println("internal exception occurred.") } } cause: jp.dely.flowsample.NetworkException, attempt: 0 cause: jp.dely.flowsample.NetworkException, attempt: 1 cause: jp.dely.flowsample.NetworkException, attempt: 2 retried over 3 times. cause: jp.dely.flowsample.InternalException, attempt: 0 internal exception occurred. Flow.letでFlowに対する任意の変換処理を適用 出来る(RxJavaのcomposeにあたる)