Generic Instance Method

reduce(_:_:)

Applies a closure that accumulates each element of a stream and publishes a final result upon completion.

Declaration

func reduce<T>(_ initialResult: T, _ nextPartialResult: @escaping (T, Upstream.Output) -> T) -> Publishers.Reduce<Publishers.Share<Upstream>, T>

Parameters

initialResult

The value the closure receives the first time it is called.

nextPartialResult

A closure that takes the previously-accumulated value and the next element from the upstream publisher to produce a new value.

Return Value

A publisher that applies the closure to all received elements and produces an accumulated value when the upstream publisher finishes.

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