Instance Method

tryFirst(where:)

Publishes the first element of a stream to satisfy a throwing predicate closure, then finishes.

Declaration

func tryFirst(where predicate: @escaping (Upstream.Output) throws -> Bool) -> Publishers.TryFirstWhere<Publishers.Share<Upstream>>

Parameters

predicate

A closure that takes an element as a parameter and returns a Boolean value that indicates whether to publish the element.

Return Value

A publisher that only publishes the first element of a stream that satifies the predicate.

Discussion

The publisher ignores all elements after the first. If this publisher doesn’t receive any elements, it finishes without publishing. If the predicate closure throws, the publisher fails with an error.

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