Created
June 30, 2021 00:07
-
-
Save markmals/11e1c10d5a06e4e59a87e48691628b16 to your computer and use it in GitHub Desktop.
A passthrough operator for Combine Publishers
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 { | |
@discardableResult | |
func passthrough(_ closure: @escaping (Result<Output, Failure>) -> Void) -> AnyPublisher<Output, Failure> { | |
map { output in | |
closure(.success(output)) | |
return output | |
} | |
.mapError { error in | |
closure(.failure(error)) | |
return error | |
} | |
.eraseToAnyPublisher() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment