11.2 · map, scan, combineLatest, flatMap, switchToLatest, debounce, share
Operators are the vocabulary. A handful cover nearly everything: transform, combine, flatten, time, and share.
Mental model. Read a pipeline top to bottom as a conveyor belt: each operator takes what arrives and decides what to pass on, and when.
Transform and combine
Reading pipelines, merging and zipping.
- How do you read a pipeline, and how do combineLatest, merge, zip and scan differ?
Read a pipeline from the source downward; each operator is a function from one publisher to another. Transform operators change values one at a time: map…
Flattening, timing and sharing
<code>flatMap</code>, <code>switchToLatest</code>, <code>debounce</code>, <code>share</code>.
- How do flatMap and switchToLatest differ, and when do you use each?
flatMap turns each upstream value into another publisher and merges all of those inner publishers’ outputs into one stream. It keeps every inner publisher… - What do debounce, throttle and removeDuplicates do, and what do share and multicast change?
Timing operators reshape when values pass. debounce(for:scheduler:) waits until the stream has been quiet for the interval and then emits only the last value…
More in Combine
- 11.1 · Publisher, Subscriber, Subscription and demand
- 11.3 · PassthroughSubject, CurrentValueSubject and @Published
- 11.4 · receive(on:), subscribe(on:) and where code runs
- 11.5 · AnyCancellable, subscription lifetime, and failure versus Never
- 11.6 · Combine versus async/await, and testing pipelines
- 11.7 · Operator behaviour, error placement, retry, flatMap limits and debugging
- 11.8 · Future versus Deferred, subject replay, share, and bridging to async
- 11.9 · Which thread each stage runs on, schedulers, throttle versus debounce, and timers
- 11.10 · Cancelling and completing, the cycle that survives a deinit, and failure types