Performing side effects

Sometimes while working with an Observable sequence, we want to perform some action or side effect when elements are emitted, which won't change anything specifically about the elements emitted. We discussed about side effects in theory back in Chapter 2, FRP Fundamentals, Terminology, and Basic Building Blocks. Now, we will see the programmatic implementation.

We can use the doOn operator to perform side effects. Think of doOn as a wire tap on an Observable sequence. You can listen to the sequence but cannot modify things, and doOn will pass through each event. The actual method includes parameters for onNext, onError, onCompleted events, and the onSubscribe and onDispose handlers. Each is optional, so you can skip ...

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.