-
-
Save jasdev/9503435250951e051b7dd0cca471b2e1 to your computer and use it in GitHub Desktop.
Non-`AnyObject` constrained forms of `Publisher.withLatestFrom`.
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
import Combine | |
extension Publisher { | |
func withLatestFrom<Other: Publisher>( | |
_ other: Other | |
) -> AnyPublisher<Other.Output, Other.Failure> | |
where Failure == Other.Failure { | |
other | |
.map { second in map { _ in second } } | |
.switchToLatest() | |
.eraseToAnyPublisher() | |
} | |
} | |
extension Publisher { | |
func withLatestFrom<Other: Publisher, Transformed>( | |
_ other: Other, | |
_ selector: @escaping (Output, Other.Output) -> Transformed | |
) -> AnyPublisher<Transformed, Other.Failure> | |
where Failure == Other.Failure { | |
other | |
.map { second in map { first in selector(first, second) } } | |
.switchToLatest() | |
.eraseToAnyPublisher() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment