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.Output<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.