Calls a closure with each received element and publishes any returned optional that has a value.
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
- Xcode 11.0+
A closure that receives a value and returns an optional value.
nil optional results of the calling the supplied closure.
compact operator performs a function similar to that of
compact in the Swift standard library: the
compact operator in Combine removes
nil elements in a publisher’s stream and republishes non-
nil elements to the downstream subscriber.
The example below uses a range of numbers as the source for a collection based publisher. The
compact operator consumes each element from the
numbers publisher attempting to access the dictionary using the element as the key. If the example’s dictionary returns a
nil, due to a non-existent key,
compact filters out the
nil (missing) elements.