Skip to content

Missing Flow operators #437

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

Closed
ZakTaccardi opened this issue Jul 16, 2018 · 9 comments
Closed

Missing Flow operators #437

ZakTaccardi opened this issue Jul 16, 2018 · 9 comments

Comments

@ZakTaccardi
Copy link

ZakTaccardi commented Jul 16, 2018

ReceiveChannel is missing some very useful extension functions

.combineLatest()
.distinctUntilChanged()
.switchMap()
.merge()
.scan()
.filterIsInstance()

Would it be possible to add these?

@elizarov
Copy link
Contributor

Yes. However, we really want to abstract aways all kinds of streams first (see #254) and then implement all the operators on top of it. I'll keep it open though. PRs are still welcome.

@ashdavies
Copy link

It would be really useful to have the filterIsInstance operator to match that of the stdlib for collections, would it make sense to create a new issue for that?

@elizarov
Copy link
Contributor

@ashdavies Please, don't create a new issue. Let's keep a list of missing operators here.

@qwwdfsad
Copy link
Collaborator

Hopefully, channel will implement the same interface as cold stream and we will implement operators once and for all

@Bluexin
Copy link

Bluexin commented Sep 8, 2018

Especially 👍 for merge, right now I have to use ugly workarounds >.<
(note how merge described by those marbles only closes when all inputs close, which is key for me)

@PaulWoitaschek
Copy link
Contributor

I'd love to see more overloads for the combineLatest operator, or at least one combineLatest operator that takes a List<Flow<*>> so I can create my T1..Tx combineLatest functions myself.

In RxJava I really often use the pattern of combining the latest emissions of an observable into a view state:

Observable.combineLatest(userStream, recipeForId(id), foodFavoritesStream, userSettingsStream, ::buildViewState)

@LouisCAD
Copy link
Contributor

LouisCAD commented May 13, 2019

A combineLatest operator that takes a List<Flow<*>> breaks type safety, and is therefore not useful IMHO.

However, I have the same use case, and I'd like to have combineLatest overloads with up to 4 or 5 parameters (in addition to the receiver) to merge latest values of flows into a data class.

I set 4 or 5 as the hard limit because beyond that point, it's unlikely the code is readable, and intermediate combined flows should be used instead (possibly using Pair<A, B> to take advantage of destructuring).

Is that blocked by receiveOrClosed (#330) not there yet because of the function with the following signature private fun CoroutineScope.asFairChannel(flow: Flow<*>): Channel<Any>?
If not, I can work on a PR, let me know.

@elizarov elizarov changed the title missing ReceiveChannel operators Missing Flow operators May 15, 2019
@elizarov elizarov added the flow label May 15, 2019
@qwwdfsad
Copy link
Collaborator

qwwdfsad commented Jul 3, 2019

All of them have been eventually implemented

@qwwdfsad qwwdfsad closed this as completed Jul 3, 2019
@ZakTaccardi
Copy link
Author

Merge is still missing, but filed #1491

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

No branches or pull requests

7 participants