Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Observer with a generic typealias? #319

Closed
andersio opened this issue Apr 10, 2017 · 0 comments
Closed

Replace Observer with a generic typealias? #319

andersio opened this issue Apr 10, 2017 · 0 comments
Labels

Comments

@andersio
Copy link
Member

andersio commented Apr 10, 2017

Observers can now be represented using a generic typealias, since they carry no context other than the closure:

extension Signal {
    public typealias Observer<Value, Error> = (Event<Value, Error>) -> Void
}

Without the shorthands, it doesn't seem to hurt the legibility at call site.

observer.send(value: 1)
observer(.value(1))

observer.sendCompleted()
observer(.completed)

observer.sendInterrupted()
observer(.interrupted)

observer.send(error: Error())
observer(.failed(error))

The downside is impossible migration.

Related: Observer was introduced in ReactiveCocoa/ReactiveCocoa#2442 to replace the send* free functions and Event.Sink.

@andersio andersio changed the title Remove Observer the class. Remove Observer the class? Apr 10, 2017
@andersio andersio changed the title Remove Observer the class? Replace Observer with a generic typealias? Apr 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant