<!--
{
  "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_____AA10PublishersO6Merge7Vy_xqd__qd_0_qd_1_qd_2_qd_3_qd_4_Gqd___qd_0_qd_1_qd_2_qd_3_qd_4_tAaBRd__AaBRd_0_AaBRd_1_AaBRd_2_AaBRd_3_AaBRd_4_7FailureQyd__AKRtz6OutputQyd__ANRtzAKQyd_0_ALRSANQyd_0_AORSAKQyd_1_AQRSANQyd_1_ARRSAKQyd_2_ASRSANQyd_2_ATRSAKQyd_3_AURSANQyd_3_AVRSAKQyd_4_AWRSANQyd_4_AXRSr4_lF"
  },
  "title" : "merge(with:_:_:_:_:_:)"
}
-->

# merge(with:_:_:_:_:_:)

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

```
func merge<B, C, D, E, F, G>(with b: B, _ c: C, _ d: D, _ e: E, _ f: F, _ g: G) -> Publishers.Merge7<Self, B, C, D, E, F, G> where B : Publisher, C : Publisher, D : Publisher, E : Publisher, F : Publisher, G : Publisher, Self.Failure == B.Failure, Self.Output == B.Output, B.Failure == C.Failure, B.Output == C.Output, C.Failure == D.Failure, C.Output == D.Output, D.Failure == E.Failure, D.Output == E.Output, E.Failure == F.Failure, E.Output == F.Output, F.Failure == G.Failure, F.Output == G.Output
```

## Parameters

`b`

A second publisher.

`c`

A third publisher.

`d`

A fourth publisher.

`e`

A fifth publisher.

`f`

A sixth publisher.

`g`

A seventh 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(_:_:_:)-48buc).
To combine elements from multiple upstream publishers, use [`zip(_:_:_:)`](/documentation/Combine/Publisher/zip(_:_:_:)-16rcy).

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>()
let pubD = PassthroughSubject<Int, Never>()
let pubE = PassthroughSubject<Int, Never>()
let pubF = PassthroughSubject<Int, Never>()
let pubG = PassthroughSubject<Int, Never>()

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

pubA.send(1)
pubB.send(40)
pubC.send(90)
pubD.send(-1)
pubE.send(33)
pubF.send(44)
pubG.send(54)

pubA.send(2)
pubB.send(50)
pubC.send(100)
pubD.send(-2)
pubE.send(33)
pubF.send(33)
pubG.send(54)

//Prints: "1 40 90 -1 33 44 54 2 50 100 -2 33 33 54"
```

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)