Generic Instance Method

zip(_:_:)

Combines elements from two other publishers and delivers groups of elements as tuples.

Declaration

func zip<P, Q>(_ publisher1: P, _ publisher2: Q) -> Publishers.Zip3<Publishers.Zip3<A, B, C>, P, Q> where P : Publisher, Q : Publisher, Self.Failure == P.Failure, P.Failure == Q.Failure

Parameters

publisher1

A second publisher.

publisher2

A third publisher.

Return Value

A publisher that emits groups of elements from the upstream publishers as tuples.

Discussion

The returned publisher waits until all three publishers have emitted an event, then delivers the oldest unconsumed event from each publisher as a tuple to the subscriber. For example, if publisher P1 emits elements a and b, and publisher P2 emits elements c and d, and publisher P3 emits the event e, the zip publisher emits the tuple (a, c, e). It won’t emit a tuple with elements b or d until P3 emits another event. If any upstream publisher finishes successfuly or fails with an error, the zipped publisher does the same.