Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active May 23, 2020
Embed
What would you like to do?
Condensed CombineExt.Publisher.zip
extension Publisher {
func zip<Others: Collection>(with others: Others)
-> AnyPublisher<[Output], Failure>
where Others.Element: Publisher,
Others.Element.Output == Output,
Others.Element.Failure == Failure {
let seed = map { [$0] }.eraseToAnyPublisher() /// 1.
return others
.reduce(seed) { zipped, next in
zipped
.zip(next) /// 2.
.map { $0.0 + [$0.1] }
.eraseToAnyPublisher()
}
.eraseToAnyPublisher()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment