Skip to content

Instantly share code, notes, and snippets.

@jasdev
Created April 14, 2020 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdev/3b943c654931735f6c338204d58dc3db to your computer and use it in GitHub Desktop.
Save jasdev/3b943c654931735f6c338204d58dc3db to your computer and use it in GitHub Desktop.
Broken `cherReplayingLatest` attempt.
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