-
-
Save jasdev/5ffeafb41b933aba8bb0740384715db5 to your computer and use it in GitHub Desktop.
`AnyObject`-constrained `withLatestFrom` overload
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
extension Publisher where Self: AnyObject { | |
func withLatestFrom<Other: Publisher>( | |
_ other: Other | |
) -> AnyPublisher<Other.Output, Other.Failure> | |
where Failure == Other.Failure { | |
other | |
.map { [weak self] second in | |
self?.map { _ in second }.eraseToAnyPublisher() ?? | |
Empty().eraseToAnyPublisher() | |
} | |
.switchToLatest() | |
.eraseToAnyPublisher() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment