Skip to content

Instantly share code, notes, and snippets.

@markmals
Created June 30, 2021 00:07
Show Gist options
  • Save markmals/11e1c10d5a06e4e59a87e48691628b16 to your computer and use it in GitHub Desktop.
Save markmals/11e1c10d5a06e4e59a87e48691628b16 to your computer and use it in GitHub Desktop.
A passthrough operator for Combine Publishers
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