---
title: Publishers.TryCompactMap
framework: combine
role: symbol
role_heading: Structure
path: combine/publishers/trycompactmap
---

# Publishers.TryCompactMap

A publisher that republishes all non-nil results of calling an error-throwing closure with each received element.

## Declaration

```swift
struct TryCompactMap<Upstream, Output> where Upstream : Publisher
```

## Topics

### Creating a try-compact-map Publisher

- [init(upstream:transform:)](combine/publishers/trycompactmap/init(upstream:transform:).md)

### Mapping elements

- [compactMap(_:)](combine/publishers/trycompactmap/compactmap(_:).md)

### Declaring supporting types

- [Publishers.Output](combine/publishers/output.md)
- [Publishers.TryCompactMap.Failure](combine/publishers/trycompactmap/failure.md)

### Inspecting publisher properties

- [upstream](combine/publishers/trycompactmap/upstream.md)
- [transform](combine/publishers/trycompactmap/transform.md)

## Relationships

### Conforms To

- [Publisher](combine/publisher.md)

## See Also

### Filtering elements

- [Publishers.Filter](combine/publishers/filter.md)
- [Publishers.TryFilter](combine/publishers/tryfilter.md)
- [Publishers.CompactMap](combine/publishers/compactmap.md)
- [Publishers.RemoveDuplicates](combine/publishers/removeduplicates.md)
- [Publishers.TryRemoveDuplicates](combine/publishers/tryremoveduplicates.md)
- [Publishers.ReplaceEmpty](combine/publishers/replaceempty.md)
- [Publishers.ReplaceError](combine/publishers/replaceerror.md)
