Transforming operators: map, flatMap and flatMapLatest

Navdeep Singh
7 min readApr 15, 2018

RxSwift offers a range of operators that provide immense control over how you want to work with the data and events in your application.

Transforming operators are used when you want to model the data coming from a sequence to suit your requirements; in other words, prepare the data to match the requirements of a subscriber.

For example, to transform elements emitted from an Observable sequence, you use the map operator; map will transform each element as it is emitted from the source Observable sequence. This is similar to the map(_:) method in the standard Swift library, except that this map works with Observable sequence elements. A marble diagram representation of the map operator will look like this:

map(_:) in action

We will go through an example of using map in the playground. We will need our helper function, that is, executeProcedure(with description:String, procedure: () -> Void). This function takes two params: a string description and a procedure closure . It then prints the description, followed by the execution of the procedure.

public func…

--

--

Navdeep Singh

Author of Reactive programming with Swift, Engineering Manager — Exploring possibilities with new Tech.