Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active Apr 4, 2021
Embed
What would you like to do?
`AnyObject`-constrained `withLatestFrom` overload
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