https://kotlinlang.org logo
#flow
Title
# flow
j

Jeziel Lago

05/11/2021, 6:12 PM
Hi 👋🏼 How can I replace Rx operator
repeat
with some Flow operator?
e

ephemient

05/13/2021, 4:14 AM
Copy code
fun <T> Flow<T>.repeat(): Flow<T> = flow {
    while (true) emitAll(this@repeat)
}
j

Jeziel Lago

05/13/2021, 11:09 AM
I have to create my Flow operator, right? maybe like that:
Copy code
fun <T> Flow<T>.repeat(times: Int): Flow<T> = flow {
    repeat (times) { emitAll(this@repeat) }
}
I opened a PR with something like that https://github.com/Kotlin/kotlinx.coroutines/pull/2702
e

ephemient

05/13/2021, 10:57 PM
Copy code
public fun <T> Flow<T>.repeatUntil(condition: () -> Boolean): Flow<T>
should take a
suspend () -> Boolean
lambda, at least… maybe even
suspend FlowCollector<T>.() -> Boolean
4 Views