doOn in action

Let's work with doOn in code. We will use the same playground page, and start by commenting out the implementation so far. We will create a bare-bones implementation of the method for doOn and inside the implementation we will declare a disposeBag, as follows:

executeProcedure(for: "do(on....:)") {         let disposeBag = DisposeBag()    }

Then, we will create a PublishSubject of the Int type:

let temperatureInFahrenheit = PublishSubject<Int>()

This PublishSubject will hold values that are temperatureInFahrenheit that we want to convert to Celsius.

We will chain a do(onNext:) operator on to the sequence and in it, multiply the element by itself. Although we could work with the result of this calculation within the do(onNext:) handler, ...

Get Reactive Programming with Swift 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.