Chapter 9

How can you print something each time an item is emitted?

It is possible to implement a side-effect without changing the items emitted on an operator chain by using the do_action operator. This operator allows us to call a function on each event type received from its source observable.

How can you compute a value from all the items of an observable?

Two operators can be used to compute a value from all items emitted on an observable: the scan and the reduce operators. Both operators call a function for each item, with an accumulator as input (on top of the item itself). This function must return the updated value of the accumulator.

The difference between scan and reduce is that scan emits the value of the accumulator for each item, while reduce only emits the value when the source observable completes.

How can you subscribe to the latest observable emitted by a higher-order observable?

When an observable emits items that are themselves observables, it is possible to subscribe only to the most recent child observable with the switch_latest operator.

How can you combine values of several observables, item by item?

The zip operator makes an item-by-item computation from several observables. Each time all source observables emit an item, a combined item is computed from these items.

How can you retrieve the first item of an observable?

Retrieving the first item of an observable is implemented by the first operator. Similarly, the last item can be retrieved with the last operator.

How can you classify items of an observable, based on some criteria?

The group_by operator takes a single observable and returns a higher-order observable. This higher-order observable contains one observable per class in the source observable.

How can you drop some elements of an observable based on some criteria?

The skip_while operator drops all items from its source observable until a criterion is fulfilled on the received items.

How can you chain several observable, one after the other?

You can chain several observables with the concat operator. The concat operator differs from the merge operator in the following way: the merge operator emits the items of all its source observables as they arrive (the items are interleaved), while the concat operator keeps the sequence of each observable (the items of one observable are emitted once the previous observable completed).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.90.182