Kotlinx.coroutines: Provide Flow operators for UI programming

Created on 17 Apr 2019  路  8Comments  路  Source: Kotlin/kotlinx.coroutines

There is a family of operators which are widespread in UI but which are tricky to implement (especially with current select statement):
-- switchMap
-- debounce (throttle and sample?)
-- takeUntil(flow) (?)

flow

Most helpful comment

switchMap feels essential in general.

I definitely think having an at-most-every operator is essential. Where you want notifications at most every, say, 1 second. The key part of this is that if 1.5 seconds elapse, the next notification is received instantly. RxJava calls this throttleLatest and its behavior is different from debounce, throttleFirst, and throttleLast.

All 8 comments

Maybe @JakeWharton and @gildor could point a few more necessary operators?

switchMap feels essential in general.

I definitely think having an at-most-every operator is essential. Where you want notifications at most every, say, 1 second. The key part of this is that if 1.5 seconds elapse, the next notification is received instantly. RxJava calls this throttleLatest and its behavior is different from debounce, throttleFirst, and throttleLast.

If we are talking about UI programming debounce, throttleLatest and sample are very common and we use them a lot in many cases when we want to limit the amount of events from UI or to UI

And agree with Jar, switchMap is just essential

Thanks for your advice!

1132 says:

Partially fixes #1107

So is this issue really fixed? Or has it been closed by mistake?

So is this issue really fixed?

Partially :) switchMap, debounce and sample are here.
For conflate and friends I will create another issue (it has some non-trivial design issues)

Could an operator like the following be added? The debounce operator is already added, but I need one with a different timeout depending on the item. It shouldn鈥檛 be too difficult to modify the current operator to add this. I can explain my use case for this operator if needed.

fun <T> Flow<T>.debounce(timeoutMillis: (T) -> Long): Flow<T>

Please explain and create a separate issue for that

Was this page helpful?
0 / 5 - 0 ratings