Created
April 14, 2020 21:16
-
-
Save jasdev/3b943c654931735f6c338204d58dc3db to your computer and use it in GitHub Desktop.
Broken `cherReplayingLatest` attempt.
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
extension Publisher { | |
func cherReplayingLatest() -> Publishers.CompactMap< | |
Publishers.Autoconnect< | |
Publishers.Multicast< | |
Publishers.Map<Self, Output?>, | |
CurrentValueSubject<Output?, Failure> | |
> | |
>, | |
Output | |
> { | |
map(Optional.some) /// (1) To give the subject below an initial value, we can box upstream | |
/// in an `Optional.some` and, later, compact `nil` values out. | |
.multicast { CurrentValueSubject(nil) } /// (2) Swapping in a `CurrentValueSubject`. | |
.autoconnect() | |
.compactMap { $0 } /// (3) Dropping `nil`s. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment