June 2017
Beginner to intermediate
274 pages
6h 49m
English
For our demo, we'll make a program that prints messages loosely representing the sounds we might hear in a zoo. The animals will be represented as observables emitting events, representing sounds at random intervals. We'll use merging and mapping to combine and modify the event sequences, before finally printing out the resulting sequence.
So, first of all, we have our Animal class, which is an observable, and the AnimalEvent helper class. The Animal class contains some basic information and a coroutine, which will run asynchronously and occasionally send events to the observers of the Animal class as shown in the following code example:
Looking at the preceding code, we can see that an animal is effectively ...
Read now
Unlock full access