-
-
Save jasdev/17e11cffe79567d2b1334d1fcdbd22e8 to your computer and use it in GitHub Desktop.
Condensed CombineExt.Publisher.zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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