Created
October 25, 2020 09:04
-
-
Save erdemildiz/4729d4cec9ab178e8c3f9e75844fdbcd to your computer and use it in GitHub Desktop.
Publisher extension - asResult
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
// Source: https://www.swiftbysundell.com/articles/the-power-of-extensions-in-swift/ | |
extension Publisher { | |
func asResult() -> AnyPublisher<Result<Output, Failure>, Never> { | |
self.map(Result.success) | |
.catch { error in | |
Just(.failure(error)) | |
} | |
.eraseToAnyPublisher() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage