<!--
{
  "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:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine9PublisherPAAE5merge4with_AA10PublishersO6Merge3Vy_xqd__qd_0_Gqd___qd_0_tAaBRd__AaBRd_0_7FailureQyd__AKRtz6OutputQyd__ANRtzAKQyd_0_ALRSANQyd_0_AORSr0_lF"
  },
  "title" : "merge(with:_:)"
}
-->

# merge(with:_:)

Combines elements from this publisher with those from two other publishers, delivering an interleaved sequence of elements.

```
func merge<B, C>(with b: B, _ c: C) -> Publishers.Merge3<Self, B, C> where B : Publisher, C : Publisher, Self.Failure == B.Failure, Self.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output
```

## Parameters

`b`

A second publisher.

`c`

A third publisher.

## Return Value

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

## Discussion

Use [`merge(with:_:)`](/documentation/Combine/Publisher/merge(with:_:)) 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(_:_:)-5crqg).
To combine elements from multiple upstream publishers, use [`zip(_:_:)`](/documentation/Combine/Publisher/zip(_:_:)-8d7k7).

In this example, as [`merge(with:_:)`](/documentation/Combine/Publisher/merge(with:_:)) receives input from the upstream publishers, it republishes the interleaved elements to the downstream:

```
let pubA = PassthroughSubject<Int, Never>()
let pubB = PassthroughSubject<Int, Never>()
let pubC = PassthroughSubject<Int, Never>()

cancellable = pubA
    .merge(with: pubB, pubC)
    .sink { print("\($0)", terminator: " " )}

pubA.send(1)
pubB.send(40)
pubC.send(90)
pubA.send(2)
pubB.send(50)
pubC.send(100)

// Prints: "1 40 90 2 50 100"
```

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)