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

Paul Woitaschek

09/07/2018, 3:17 PM
Now I want to combine these two so I can expose another channel of
data class Person(val userName : String, age : Int)
v

Vsevolod Tolstopyatov [JB]

09/07/2018, 3:42 PM
Now I want to combine these two so I can expose another channel of
data class Person(val userName : String, age : Int)
It’s actually not a
combineLatest
semantics. For the
combineLatest
I’d recommend using
select
operator, for merging two channels
kotlinx.coroutines
has zip operator: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental.channels/zip.html
p

Paul Woitaschek

09/07/2018, 3:44 PM
Why is it not a
combineLatest
semantic?
v

Vsevolod Tolstopyatov [JB]

09/07/2018, 3:49 PM
ch1: “John” ch2: 30 ch2: 32 combine latest over these two channels will produce
Person("John", 30), Person("John", 32)
, it’s not a desired behavior for a person example, is it?
p

Paul Woitaschek

09/07/2018, 3:53 PM
Exactly that is desired
When the user changes it's age, that's the new state I want to render 🙂
v

Vsevolod Tolstopyatov [JB]

09/07/2018, 3:58 PM
oh, sorry then 🙂
l

louiscad

09/08/2018, 12:32 AM
@Paul Woitaschek Here's my solution, which works for any number of channels or callbacks, of any type: https://gist.github.com/LouisCAD/d9d1adbd3b4fd36d9dc121658fefd16f Let me know if you need help figuring out how to use it.
p

Paul Woitaschek

09/08/2018, 5:51 AM
Thanks, after figuring out forever I implemented it in rx and it's way simpler
My conclusion so far is that with anything stream based, rx makes it simpler where with whenever I have a rx.Single / Maybe coroutines work better
3 Views