question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Merge Flow operator is missing

See original GitHub issue

The merge() operator is missing

fun Flow<T>.merge(vararg flows: Flow<T>): Flow<T> = TODO()

Use Case

Representing clicks on a keypad:

val key1: View
val key2: View
val numberClicks: Flow<Int> = merge(
  key1.clicks().map { 1 },
  key2.clicks().map { 2 }
)

Note: I think fun Flow<T>.merge(otherFlow: Flow<T>): Flow<T> is an anti-pattern because it creates hard to read flows, so I am intentionally not requesting it 😛

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
elizarovcommented, Sep 3, 2019

flattenMerge is in preview, because it has an optional concurrency parameter and we have not decided yet what exactly to do with it and with other “concurrent” operators (see #1147). In particular it means that if you are planning to use the above merge implementation with more than 16 flows, then you should rewrite it like this:

fun <T> merge(vararg flows: Flow<T>): Flow<T> = 
    flowOf(*flows).flattenMerge(concurrency = flows.length)
2reactions
elizarovcommented, Sep 18, 2019

The “gotcha” with concurrency limit is a strong motivator for a separate merge operator.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Combining flows: merge, zip, and combine - Kt. Academy
Let's talk about combining two flows into one. There are a few ways to do this. The simplest involves merging the elements from...
Read more >
Flow Operators in Assignment Elements - Salesforce Help
Use Assignment element operators to change the value of a selected resource. ... In Flow Builder, we replaced sObject with the Record data...
Read more >
Android: Application gets stuck in flow combine and does not ...
I'd suspect that one of your flows is actually empty. Could you ensure that both of them are emitting values?
Read more >
Merge operator - IBM
A data flow diagram showing the merge operator being used to merge data from a number of update data sets with data from...
Read more >
From Zero To Hero Series ( Kotlin Sequences, Channels ...
Flows have zip and combine operator that combines the corresponding values ... Kotlin coroutines were missing a primitive to represent cold ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found