I don't get the rxjava coroutines. Isn't the rxjav...
# coroutines
p
I don't get the rxjava coroutines. Isn't the rxjava specifically designed for thread switching and combining data flows? What benefit do coroutines give?
e
paulwoitaschek: The primary benefit of coroutines is that you can encode your async computations explicitly, without having to resort to callbacks (aka callback hell) nor to combinators/FP (aka RX) neither of which scale to complex business logic. More examples are given in coroutines design doc: https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md
p
So if its designed so one does not have to use rx, why is there a rx module?
e
For the same reasons as there is jkd8 module with
CompletableFuture
. For interop in large project which you cannot just rewrite all to coroutines
Also, Rx and coroutines can augment each other.
Like we have
for
statement in Kotlin, but also
filter
,
map
, etc in stdlib.
You can express many data flows with combinators, but some dataflows and dependencies either cannot be expressed at all or produce complete inntelligible code when written with cobinators.
❤️ 1
So, if you have a stream of events and you want to map a function over it, then Rx combinators are the natural way to express that. However, if you have some complex enterprise business logic where async calls are burried deep inside its subroutines, then goodluck rewriting it with Rx.
❤️ 1
a
@elizarov so its possible to encode the Rx stream with coroutines? I only saw the singles in the experimental library
p
How about stuff like switchMap
e
It is possible. Rx module is just a trivial sample now. It will be expanded in the future. The are stream-production examples (with support for iteration with
for
loops) in the design document I've linked to
p
And jdk8 won't arrive on Android soon
e
You don't need jdk8
a
I remember seeing a tutorial for coroutines somewhere on the web, but i can't seem to find it now
e
They are not released yet 🙂 But you can look and a draft guide for
kotlinx.coroutines
here: https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md
a
thank you!