Calls a closure with each received element and publishes any returned optional that has a value.
SDKs
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
- Xcode 11.0+
Framework
- Combine
Declaration
func compactMap<T>(_ transform: @escaping (Output) -> T?) -> Publishers.Compact Map<Publishers.Map<Upstream, Output>, T>
Parameters
transform
A closure that receives a value and returns an optional value.
Return Value
A publisher that republishes all non-nil
results of calling the transform closure.