Publisher.zip completions
23 Jan 2021 ⇐ Notes archive(This is an entry in my technical notebook. There will likely be typos, mistakes, or wider logical leaps — the intent here is to “let others look over my shoulder while I figure things out.”)
Zipping — in general — is a pairwise affair. Optional
’s zip
is non-nil
if both arguments are. Similarly for Result
’s zip
along the .success
case. Swift.zip
pairs until it runs off the shorter of the sequence arguments. Parsers.Take2
(another name for zipped parsing) succeeds if both parsers involved do.
While Publisher.zip
and its higher-arity overloads follow suit for value events, there’s a subtle gotcha for .finished
events (failures are immediately passed downstream).
A zipped publisher can complete even if all of its inner publishers don’t.
This checks out after a pause — since second
completes after the first (1, 2)
pair comes through, there’s no chance it’ll pair with any future value events from first
. Hence the completion. So, even though zipping is usually synonymous with “pairing” in my head, I’ll need to remember that doesn’t necessarily extend to completion events.