Title
p

Paul Woitaschek

01/31/2017, 10:04 AM
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

elizarov

01/31/2017, 10:22 AM
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

Paul Woitaschek

01/31/2017, 10:25 AM
So if its designed so one does not have to use rx, why is there a rx module?
e

elizarov

01/31/2017, 10:27 AM
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

adeln

01/31/2017, 10:37 AM
@elizarov so its possible to encode the Rx stream with coroutines? I only saw the singles in the experimental library
p

Paul Woitaschek

01/31/2017, 10:38 AM
How about stuff like switchMap
e

elizarov

01/31/2017, 10:38 AM
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

Paul Woitaschek

01/31/2017, 10:39 AM
And jdk8 won't arrive on Android soon
e

elizarov

01/31/2017, 10:39 AM
You don't need jdk8
a

adeln

01/31/2017, 10:40 AM
I remember seeing a tutorial for coroutines somewhere on the web, but i can't seem to find it now
e

elizarov

01/31/2017, 10:41 AM
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

adeln

01/31/2017, 10:45 AM
thank you!