Episode 1
How to Use Combine's Map and CompactMap Operators
In this episode of[Combine Essentials, we take a look at two of Combine's most commonly used operators, map and compactMap.
In this episode of[Combine Essentials, we take a look at two of Combine's most commonly used operators, map and compactMap.
Combine's filter and compactMap operators share a few similarities and it is possible to use them interchangeably in some scenarios. That said, there are a number of key differences we discuss in today's episode of Combine Essentials.
This episode of Combine Essentials zooms in on Combine's merge operator. As the name suggests, the merge operator merges two or more upstream publishers into a single publisher. Even though the merge operator isn't difficult to use, there are a few pitfalls to watch out for.
In an earlier installment of Combine Essentials, you learned about Combine's map operator, one of the most commonly used operators. The map operator has one important limitation. The closure you pass to the map operator can't be throwing. Don't worry, though. Combine's tryMap operator addresses this shortcoming.
Every Combine publisher defines two associated types, the Output type defines the type of elements the publisher can emit and the Failure type defines the type of errors the publisher can emit. The fact that a publisher is required to define an Output type and a Failure type is convenient, but it can sometimes be inconvenient.
What I love most about RxSwift is RxCocoa. RxCocoa defines a wide range of integrations with UIKit and AppKit. It is surprising that Apple's Combine framework lacks these integrations. The good news is that most of the integrations RxCocoa defines are easy to implement using Combine. In this episode, I show you how to observe the value of a UITextField instance using the Combine framework.
The Combine framework defines a number of operators to combine two or more publishers into a single publisher. Each of these operators serves a specific purpose. In this episode, I show you how to use the zip operator to combine publishers.
Earlier in this series, I explained how you can use Combine's compactMap operator to filter out nil elements emitted by a publisher. While this is a common use case, there are scenarios in which you don't want to filter out nil elements. Instead you want to replace the nil elements with a default or fallback value. In this episode of Combine Essentials, you learn about the replaceNil operator to do just that. Note that I don't recommend developers to use the replaceNil operator due to its unintuitive behavior. I explain this in more detail in this episode.
A publisher is nothing more than a sequence of elements over time. Your application typically performs an action when a publisher emits an element. In some scenarios, the action you take requires the elements the publisher emitted up until that point. That is where the scan and tryScan operators come in useful. This may sound confusing so let's take a look at an example.