Generic Instance Method

zip(_:_:)

Combines elements from another publisher and delivers a transformed output.

Declaration

func zip<P, T>(_ other: P, _ transform: @escaping ((A.Output, B.Output, C.Output, D.Output), P.Output) -> T) -> Publishers.Map<Publishers.Zip<Publishers.Zip4<A, B, C, D>, P>, T> where P : Publisher, Self.Failure == P.Failure

Parameters

other

Another publisher.

transform

A closure that receives the most recent value from each publisher and returns a new value to publish.

Return Value

A publisher that uses the transform closure to emit new elements, produced by combining the most recent value from two upstream publishers.

Discussion

The returned publisher waits until both publishers have emitted an event, then delivers the oldest unconsumed event from each publisher together as a tuple to the closure. For example, if publisher P1 emits elements a and b, and publisher P2 emits event c, the transform closure receives the tuple (a, c). The closure won’t receive a tuple with event b until P2 emits another event. If either upstream publisher finishes successfully or fails with an error, the zipped publisher does the same.