https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

tseisel

07/23/2019, 2:00 PM
Is there a better syntax for collecting a
Flow
to a
Channel
than the following ?
Copy code
flow {
    coroutineScope {
        val channel = produce {
            aFlow.collect { send(it) }
        }
    }
}
I want to write a custom logic for combining 2 `Flow`s,
zip
and
combineLatest
don't fit my use case.
s

streetsofboston

07/23/2019, 2:12 PM
You could look at the source-code of
zip
and
combineLatest
, copy it and then modify it for your use-case.
z

Zach Klippenstein (he/him) [MOD]

07/23/2019, 5:20 PM
val channel = aFlow.produceIn(this)
It’s more concise, but it also integrates with channel operator fusion so if the source flow is already backed by a channel, it won’t (necessarily) create another one.
💯 2
3 Views