Contents

min()

Publishes the minimum value received from the upstream publisher, after it finishes.

Declaration

func min() -> Publishers.Comparison<Self>

Return Value

A publisher that publishes the minimum value received from the upstream publisher, after the upstream publisher finishes.

Discussion

Use min(by:) to find the minimum value in a stream of elements from an upstream publisher.

In the example below, the min(by:) operator emits a value when the publisher finishes, that value is the minimum of the values received from upstream, which is -1.

let numbers = [-1, 0, 10, 5]
numbers.publisher
    .min()
    .sink { print("\($0)") }

// Prints: "-1"

After this publisher receives a request for more than 0 items, it requests unlimited items from its upstream publisher.

See Also

Applying mathematical operations on elements