Learn how you can use operators such as switchToLatest, merge(with:), combineLatest and zip to perform more advanced combinations of data from publisher.
This content was released on Feb 4 2021. The official support period is 6-months
from this date.
Learn how you can use operators such as switchToLatest, merge(with:), combineLatest and zip to perform more advanced combinations of data from publisher.
Cinema mode
Mark complete
Download course materials
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous episode: 17. Challenge: Append and Prepend
Next episode: 19. Operator Examples
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Now let's talk about some more complex combining operators. I'll explain each of them with a marble diagram and then we'll see them in a demo. SwitchToLatest is complex, but very useful. It lets you switch entire publisher subscriptions on the fly while canceling the existing publisher subscription. You can only use it on publishers that themselves emit publishers. This marble diagram shows that the publisher on the top of the operator is actually a publisher of publishers. Numbers one is published first and while values are being emitted, the publisher switches to numbers two and cancels publisher one. The mergewith operator interleaves emissions from different publishers of the same type. In the marble diagram, you see the original publisher, which emits one, two, and four, gets merged with publisher two which emits three and five. The sequence one, two, three, four, five is sent downstream. CombineLatest not only lets you combine values from two publishers, it also allows for those values to be of separate types. CombineLatest, however, doesn't interleave like merge does. Instead, it forms a tuple of the latest values from each publisher and emits that tuple to the downstream consumer. The catch here is that each publisher must have emitted at least one value for CombineLatest to emit anything. And finally, zip emits tuples like CombineLatest, but forms the tuples of the same index across all publishers. The marble diagram shows the first tuple emission once the original publisher and publisher two have emitted their first value. The next tuple occurs after both have emitted their second values and so on. With those concepts in hand, let's look at these operators in a demo which we'll do in the next episode.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.