O'Reilly logo

Reactive Programming with Swift 4 by Navdeep Singh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

flatMap and flatMapLatest in action

In the previous section, we read about three transforming operators and saw the map operator in action. In this subsection, we will work with flatMap and flatMapLatest and see how we can implement these operators in a code base. Let's start with flatMap.

Switch over to the playground and comment out the code that we wrote so far in order to segregate the outputs of these operators from map which was implemented earlier.

First, we will declare a GamePlayer struct with a playerScore property that is a Variable event of the Int type. We will also declare a disposeBag, as follows:

executeProcedure(for: "flatMap and flatMapLatest") {        struct GamePlayer {        let playerScore: Variable<Int>    }    let disposeBag = DisposeBag ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required