Concatenating and prefixing

While working with Observables, one of the most obvious requirements is to provide an initial or starting value to an observer. Some examples of this use case come into use while working with locations service and network connectivity when it becomes essential to provide an initial state to the observer; startWith is one such operator that allows us to prefix an initial value.

Let's work with its implementation in detail—startWith will prepend or add an Observable sequence to the beginning of the source Observable sequence, and those elements will be emitted before beginning to emit elements from the source Observable sequence.

The following describes the functionality of startWith:

Let's work with startWith

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.