Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1 KB

TraitPublishers-ZipSingle.md

File metadata and controls

39 lines (30 loc) · 1 KB

TraitPublishers.ZipSingle

TraitPublishers.ZipSingle is a single Publisher that zips several single publishers together and publishes one array of all published elements.

struct ZipSingle<UpstreamCollection>: SinglePublisher
where UpstreamCollection: Collection,
      UpstreamCollection.Element: Publisher
{
    /// The zipped collection
    let collection: UpstreamCollection
    
    /// Creates a `ZipSingle` publisher
    init(collection: UpstreamCollection)
}

TraitPublishers.ZipSingle exists as a complement to the Combine Publishers.Zip, Zip3 and Zip4 that supports any number of publishers.

When the zipped collection is empty, ZipSingle publishes an empty array.

Usage

let collection = [
    Just(1),
    Just(2),
]
let publisher = collection.zipSingle()
_ = publisher.sink { values in
    print(values) // prints "[1, 2]"
}