---
title: "init(upstream:transform:)"
framework: combine
role: symbol
role_heading: Initializer
path: "combine/publishers/compactmap/init(upstream:transform:)"
---

# init(upstream:transform:)

Creates a publisher that republishes all non-nil results of calling a closure with each received element.

## Declaration

```swift
init(upstream: Upstream, transform: @escaping (Upstream.Output) -> Output?)
```

## Parameters

- `upstream`: The publisher from which this publisher receives elements.
- `transform`: A closure that receives values from the upstream publisher and returns optional values.
