Generic Instance Method

tryCompactMap(_:)

Calls an error-throwing closure with each received element and publishes any returned optional that has a value.

Declaration

func tryCompactMap<T>(_ transform: @escaping (Upstream.Output) throws -> T?) -> Publishers.TryCompactMap<Publishers.Share<Upstream>, T>

Parameters

transform

an error-throwing 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.

Discussion

If the closure throws an error, the publisher cancels the upstream and sends the thrown error to the downstream receiver as a Failure.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software