Instance Method


Collects up to the specified number of elements, and then emits a single array of the collection.


func collect(_ count: Int) -> Publishers.CollectByCount<Publishers.Share<Upstream>>



The maximum number of received elements to buffer before publishing.

Return Value

A publisher that collects up to the specified number of elements, and then publishes them as an array.


If the upstream publisher finishes before filling the buffer, this publisher sends an array of all the items it has received. This may be fewer than count elements. If the upstream publisher fails with an error, this publisher forwards the error to the downstream receiver instead of sending its output. Note: When this publisher receives a request for .max(n) elements, it requests .max(count * n) from the upstream publisher.

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