---
title: "zip(_:_:)"
framework: combine
role: symbol
role_heading: Instance Method
path: "combine/publisher/zip(_:_:)-8d7k7"
---

# zip(_:_:)

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

## Declaration

```swift
func zip<P, Q>(_ publisher1: P, _ publisher2: Q) -> Publishers.Zip3<Self, 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

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

## Discussion

Discussion Use zip(_:_:) to return a new publisher that combines the elements from two additional publishers to publish a tuple to the downstream. 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. In this example, numbersPub, lettersPub and emojiPub are each a PassthroughSubject; zip(_:_:) receives the oldest unconsumed value from each publisher and combines them into a tuple that it republishes to the downstream: let numbersPub = PassthroughSubject<Int, Never>() let lettersPub = PassthroughSubject<String, Never>() let emojiPub = PassthroughSubject<String, Never>()

cancellable = numbersPub     .zip(lettersPub, emojiPub)     .sink { print("\($0)") } numbersPub.send(1)     // numbersPub: 1      lettersPub:          emojiPub:        zip output: <none> numbersPub.send(2)     // numbersPub: 1,2    lettersPub:          emojiPub:        zip output: <none> numbersPub.send(3)     // numbersPub: 1,2,3  lettersPub:          emojiPub:        zip output: <none> lettersPub.send("A")   // numbersPub: 1,2,3  lettersPub: "A"      emojiPub:        zip output: <none> emojiPub.send("😀")    // numbersPub: 2,3    lettersPub: "A"      emojiPub: "😀"   zip output: (1, "A", "😀") lettersPub.send("B")   // numbersPub: 2,3    lettersPub: "B"      emojiPub:        zip output: <none> emojiPub.send("🥰")    // numbersPub: 3      lettersPub:          emojiPub:        zip output: (2, "B", "🥰")

// Prints: //  (1, "A", "😀") //  (2, "B", "🥰") If any upstream publisher finishes successfully or fails with an error, so too does the zipped publisher.

## See Also

### Collecting and republishing the oldest unconsumed elements from multiple publishers

- [zip(_:)](combine/publisher/zip(_:).md)
- [zip(_:_:)](combine/publisher/zip(_:_:)-4xn21.md)
- [zip(_:_:_:)](combine/publisher/zip(_:_:_:)-9yqi1.md)
- [zip(_:_:_:)](combine/publisher/zip(_:_:_:)-16rcy.md)
- [zip(_:_:_:_:)](combine/publisher/zip(_:_:_:_:).md)
