December 2017
Intermediate to advanced
322 pages
7h 3m
English
So, now that we are somewhat familiar with observables, let's modify the even-odd program in a reactive way. Here is the code for doing so:
fun main(args: Array<String>) {
var subject:Subject<Int> = PublishSubject.create()
subject.map({ isEven(it) }).subscribe({println ("The number is ${(if (it) "Even" else "Odd")}" )})
subject.onNext(4)
subject.onNext(9)
}
Here is the output:

In this program, we have used subject and map, which we will cover in the later chapters. Here, it is just to show how easy it is in reactive programming to notify the changes. If you look at the program closely, then you'll also find that ...
Read now
Unlock full access