---
title: "flatMap(maxPublishers:_:)"
framework: combine
role: symbol
role_heading: Instance Method
path: "combine/publisher/flatmap(maxpublishers:_:)-4of8w"
---

# flatMap(maxPublishers:_:)

Transforms all elements from an upstream publisher into a new publisher up to a maximum number of publishers you specify.

## Declaration

```swift
func flatMap<P>(maxPublishers: Subscribers.Demand = .unlimited, _ transform: @escaping (Self.Output) -> P) -> Publishers.FlatMap<Publishers.SetFailureType<P, Self.Failure>, Self> where P : Publisher, P.Failure == Never
```

## Parameters

- `maxPublishers`: Specifies the maximum number of concurrent publisher subscriptions, or doc://com.apple.Combine/documentation/Combine/Subscribers/Demand/unlimited if unspecified.
- `transform`: A closure that takes an element as a parameter and returns a publisher that produces elements of that type.

## Return Value

Return Value A publisher that transforms elements from an upstream  publisher into a publisher of that element’s type.

## See Also

### Republishing elements by subscribing to new publishers

- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-3k7z5.md)
- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-qxf.md)
- [flatMap(maxPublishers:_:)](combine/publisher/flatmap(maxpublishers:_:)-hyb0.md)
- [switchToLatest()](combine/publisher/switchtolatest()-453ht.md)
- [switchToLatest()](combine/publisher/switchtolatest()-1c51y.md)
- [switchToLatest()](combine/publisher/switchtolatest()-20v3t.md)
- [switchToLatest()](combine/publisher/switchtolatest()-9eb3r.md)
