Last active
May 17, 2020 03:18
-
-
Save CassiusPacheco/4f74c4e881cfb467c1aa8db08004c1f0 to your computer and use it in GitHub Desktop.
Wraps this publisher with a type eraser that updates the expected `Failure` from `Never` to the given type.
This file contains hidden or 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
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) | |
extension Publisher where Self.Failure == Never { | |
/// Wraps this publisher with a type eraser that updates the expected `Failure` from `Never` to the given type. | |
/// | |
/// Use `eraseToAnyPublisherFailure(to:)` to expose an instance of AnyPublisher to the downstream subscriber, rather than this publisher’s actual type. | |
/// Under the hood it updates the failure type by calling `setFailureType(to:)` applying the given type. | |
public func eraseToAnyPublisherFailure<E>(to failureType: E.Type) -> AnyPublisher<Self.Output, E> where E: Error { | |
return self | |
.setFailureType(to: failureType) | |
.eraseToAnyPublisher() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment