Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 20, 2020 15:40
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/bc1577fc1eaecc1559f1ab3e44f8206c to your computer and use it in GitHub Desktop.
Save jasdev/bc1577fc1eaecc1559f1ab3e44f8206c to your computer and use it in GitHub Desktop.
`ReplaySubject` with `Publisher` requirement.
final class ReplaySubject<Output, Failure: Error>: Subject {
typealias Output = Output
typealias Failure = Failure
private let bufferSize: Int
init(bufferSize: Int) {
self.bufferSize = bufferSize
}
func send(subscription: Subscription) { /* … */ }
func send(completion: Subscribers.Completion<Failure>) { /* … */ }
func send(_ value: Output) { /* … */ }
func receive<Subscriber: Combine.Subscriber>( /// (1) The compiler’s generated method stub unfortunately picks
/// `S` for the `Subscriber` generic. And I tend to prefer the fuller name, even though it requires a
/// `Combine.Subscriber` disambiguation. Declarative programming is hard enough as it is and throwing
/// single-letter generics at folks only makes it tougher.
///
/// Back when, Rx did the same and promoted all generics to full words in the 5.x release. See the
/// “Generic Renames Checklist” section of [this issue](https://github.com/ReactiveX/RxSwift/issues/1921#issue-430354614)
/// for details.
///
/// This method is the attachment point for subscribers to this subject. We’ll need to make sure
/// `Subscriber.Failure` and `.Input` match `Failure` and `Output`, respectively.
subscriber: Subscriber
) where Failure == Subscriber.Failure, Output == Subscriber.Input { /* … */ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment