Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Flow operators for UI programming #1107

Closed
qwwdfsad opened this issue Apr 17, 2019 · 9 comments
Closed

Provide Flow operators for UI programming #1107

qwwdfsad opened this issue Apr 17, 2019 · 9 comments
Assignees
Labels

Comments

@qwwdfsad
Copy link
Collaborator

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) (?)

@qwwdfsad qwwdfsad added the flow label Apr 17, 2019
@qwwdfsad qwwdfsad self-assigned this Apr 17, 2019
@qwwdfsad
Copy link
Collaborator Author

qwwdfsad commented Apr 17, 2019

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

@JakeWharton
Copy link
Contributor

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.

@gildor
Copy link
Contributor

gildor commented Apr 18, 2019

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

@qwwdfsad
Copy link
Collaborator Author

Thanks for your advice!

qwwdfsad added a commit that referenced this issue Apr 22, 2019
    * switchMap
    * debounce
    * sample
    * Update RxJava version to 2.2.8

Partially fixes #1107
qwwdfsad added a commit that referenced this issue Apr 22, 2019
    * switchMap
    * debounce
    * sample
    * Update RxJava version to 2.2.8

Partially fixes #1107
@jcornaz
Copy link
Contributor

jcornaz commented Apr 26, 2019

#1132 says:

Partially fixes #1107

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

@qwwdfsad
Copy link
Collaborator Author

qwwdfsad commented Apr 26, 2019

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)

@Thomas-Vos
Copy link
Contributor

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’t 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>

@qwwdfsad
Copy link
Collaborator Author

Please explain and create a separate issue for that

@kmikeevfelyx
Copy link

In case someone needs it (internet provides some ridiculous implementations):

fun <T> Flow<T>.throttleLatest(period: Duration): Flow<T> =
    flow {
        conflate().collect {
            emit(it)
            delay(period)
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants