This is Understanding Combine, written by Matt Neuburg. Corrections and suggestions are greatly appreciated (you can comment here). So are donations; please consider keeping me going by funding this work at http://www.paypal.me/mattneub. Or buy my books: the current (and final) editions are iOS 15 Programming Fundamentals with Swift and Programming iOS 14. Thank you!
Transformers and Blockers
The transformer par excellence is .map
, along with various other operators with map
in their names.
The blocker par excellence is .filter
, which looks at each incoming value and either lets it through or stops it.
The distinction between transformers and blockers is not always hard and fast, so it makes sense to treat them together. Some operators do both. For example, .compactMap
is both a transformer and a blocker: it can stop a value, or it can replace it and let the replacement pass downstream.