<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Combine",
  "identifier" : "/documentation/Combine/Publisher/merge(with:)-7qt71",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine9PublisherPAAE5merge4withAA10PublishersO5MergeVy_xqd__Gqd___tAaBRd__7FailureQyd__AKRtz6OutputQyd__ANRtzlF"
  },
  "title" : "merge(with:)"
}
-->

# merge(with:)

Combines elements from this publisher with those from another publisher, delivering an interleaved sequence of elements.

```
func merge<P>(with other: P) -> Publishers.Merge<Self, P> where P : Publisher, Self.Failure == P.Failure, Self.Output == P.Output
```

## Parameters

`other`

Another publisher.

## Return Value

A publisher that emits an event when either upstream publisher emits an event.

## Discussion

Use [`merge(with:)`](/documentation/Combine/Publisher/merge(with:)-7fk3a) when you want to receive a new element whenever any of the upstream publishers emits an element. To receive tuples of the most-recent value from all the upstream publishers whenever any of them emit a value, use [`combineLatest(_:)`](/documentation/Combine/Publisher/combineLatest(_:)). To combine elements from multiple upstream publishers, use [`zip(_:)`](/documentation/Combine/Publisher/zip(_:)).

In this example, as [`merge(with:)`](/documentation/Combine/Publisher/merge(with:)-7fk3a) receives input from either upstream publisher, it republishes it to the downstream:

```
let publisher = PassthroughSubject<Int, Never>()
let pub2 = PassthroughSubject<Int, Never>()

cancellable = publisher
    .merge(with: pub2)
    .sink { print("\($0)", terminator: " " )}

publisher.send(2)
pub2.send(2)
publisher.send(3)
pub2.send(22)
publisher.send(45)
pub2.send(22)
publisher.send(17)

// Prints: "2 2 3 22 45 22 17"
```

The merged publisher continues to emit elements until all upstream publishers finish.
If an upstream publisher produces an error, the merged publisher fails with that error.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)