/condensed_zip.swift Secret
Last active
May 23, 2020 21:14
Star
You must be signed in to star a gist
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