Skip to content

Instantly share code, notes, and snippets.

View hybridcattt's full-sized avatar

Marina Vatmakhter hybridcattt

View GitHub Profile
@hybridcattt
hybridcattt / Publishers+CombineLatestMany.swift
Last active November 18, 2021 16:28
A version of Publishers.CombineLatest4 that takes an unlimited number of publishers in an array
import Combine
extension Publishers {
static func CombineLatestMany<Output>(_ pubs: [AnyPublisher<Output, Never>]) -> AnyPublisher<[Output], Never> {
guard let firstPublisher = pubs.first else {
return Empty<[Output], Never>(completeImmediately: false).eraseToAnyPublisher()
}
let allButFirst = Array(pubs.dropFirst())