<!--
{
  "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/map(_:)-99evh",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Combine"
    ],
    "preciseIdentifier" : "s:7Combine9PublisherPAAE3mapyAA10PublishersO3MapVy_xqd__Gqd__6OutputQzclF"
  },
  "title" : "map(_:)"
}
-->

# map(_:)

Transforms all elements from the upstream publisher with a provided closure.

```
func map<T>(_ transform: @escaping (Self.Output) -> T) -> Publishers.Map<Self, T>
```

## Parameters

`transform`

A closure that takes one element as its parameter and returns a new element.

## Return Value

A publisher that uses the provided closure to map elements from the upstream publisher to new elements that it then publishes.

## Discussion

Combine’s [`map(_:)`](/documentation/Combine/Publisher/map(_:)-99evh) operator performs a function similar to that of <doc://com.apple.documentation/documentation/Swift/Sequence/map(_:)> in the Swift standard library: it uses a closure to transform each element it receives from the upstream publisher. You use [`map(_:)`](/documentation/Combine/Publisher/map(_:)-99evh) to transform from one kind of element to another.

The following example uses an array of numbers as the source for a collection based publisher. A [`map(_:)`](/documentation/Combine/Publisher/map(_:)-99evh) operator consumes each integer from the publisher and uses a dictionary to transform it from its Arabic numeral to a Roman equivalent, as a <doc://com.apple.documentation/documentation/Swift/String>.
If the [`map(_:)`](/documentation/Combine/Publisher/map(_:)-99evh)’s closure fails to look up a Roman numeral, it returns the string `(unknown)`.

```
let numbers = [5, 4, 3, 2, 1, 0]
let romanNumeralDict: [Int : String] =
   [1:"I", 2:"II", 3:"III", 4:"IV", 5:"V"]
cancellable = numbers.publisher
    .map { romanNumeralDict[$0] ?? "(unknown)" }
    .sink { print("\($0)", terminator: " ") }

// Prints: "V IV III II I (unknown)"
```

If your closure can throw an error, use Combine’s [`tryMap(_:)`](/documentation/Combine/Publisher/tryMap(_:)) operator instead.

---

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)