Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active May 23, 2020 21:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jasdev/17e11cffe79567d2b1334d1fcdbd22e8 to your computer and use it in GitHub Desktop.
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