2

I have 2 flows that i would like to merge like i used to do it in RxJava.

In Rx-Java:

Flowable.just(1).mergeWith(Flowable.just(2)).subscribe({ println(it)}) // result: 1, 2

How to replicate that in Kotlin Coroutines ? Thanks in advance.

1 Answer 1

3

flattenMerge should provide same behaviour. For example,

    val flow1 = (1..3).asFlow()
    val flow2 = (4..6).asFlow()
    flowOf(flow1, flow2).flattenMerge().collect { value ->
        println("$value")
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.