Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 5, 2020 01:40
Show Gist options
  • Save jasdev/bdbfb245e2da525d16252310aaaab5ab to your computer and use it in GitHub Desktop.
Save jasdev/bdbfb245e2da525d16252310aaaab5ab to your computer and use it in GitHub Desktop.
Implemented `setOutputType`.
extension Publisher where Output == Never {
func setOutputType<NewOutput>(to outputType: NewOutput.Type) /// (1) For the uninitiated, the `.Type`
/// and `.self` suffixes here and at (2) refer to a metatype type and a type as a value,
/// respectively. The language reference has a
/// [solid section](https://docs.swift.org/swift-book/ReferenceManual/Types.html#ID455) on the topic.
-> Publishers.Map<Self, NewOutput> {
map { _ -> NewOutput in }
}
}
Just("someString")
.eraseToAnyPublisher()
.ignoreOutput()
.setOutputType(to: String.self) /// (2) Fixing downstream’s output type to `String`.
.append("anotherStringPostFinished")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment