-
Notifications
You must be signed in to change notification settings - Fork 431
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
Introduce Generalized Event #722
Conversation
This applies final tagless encoding to You listed some things that we can do. I totally agree that this opens up possibilities. The question is what would we actually use this for? i.e. of the things we can do, which would we want to do? |
There are also some minor advantages from type-system without us even noticing. Cons are definitely the type-casting problem that we always need conversion e.g. RxSwift's IMO knowing what kind of |
The importance of |
enum SingleEvent {
case completed(Value)
case failed(Error)
case interrupted
} I don't think that would enable much reuse of the existing code. I could see using this internally to implement singles since you'd get some reuse of the internals. But from the perspective of a public API, this doesn't seem ideal. (Although it is interesting.) |
One thing I come across repeatedly is the need to also have a (different type) value for the Say for a download, it is easy to use a custom type as enum Status {
case progress(Double)
case done(Data)
} But with that, there is no guarantee that a signal with that value behaves as one might expect, namely to receive a number of progress events (with the current progress), followed by exactly one completed event (with the result) or an error. Say there was an Event that has associated values for enum ResultEvent {
case value(Value)
case completed(Completed)
case failed(Error)
} With that, you could get the guarantees from the signal semantics. Obviously this relates to other events:
|
@iv-mexx That is an interesting idea that weaves well into the concept of Linking this with #667 #201 so I can have a reference in the future. Speaking of this PR, generalizing event would be a non-goal IMO, since higher-order or specialized constructs may run their more expanded events in the baselinee event grammar, and transforming them only at the API edges. RAS at its core is streams of values after all. I am also looking to the direction of splitting the event observer sink into two (value + terminiation), so that ReactiveSwift can take advantage of large value passing optimizations, which are currently impossible due to enum packing at every level of transformation. Closing due to inactivity. |
This is an experimental PR that allows to add any event type for
GSignal<GEvent: GEventProtocol>
, which meansSignal<Value, Error>
will now be its specialization:GSignal<Event<Value, Error>>
:The main idea and overview can be found from my RxSwift gist.
Generalizing events allows to create other interesting observables e.g.
Single
,Maybe
,Completable
that are found in RxSwift and other Rx frameworks.Compared to their approach of wrapping existing
Observable<Value, Error>
to a new type, this PR's approach is more abstract and robust without relying on concreteEvent<Value, Error>
type.For example:
Void
will becomeEvent<Value, Error>
)Lastly, it is worth mentioning that core engine of
Signal
doesn't need to rely on concreteEvent<Value, Error>
butGEventProtocol
.Commits
b9295b6, 3f23750, ad48733
Organized code since
Signal
andEvent
can be clearly separated.(IMO this also improves readability of existing codebase which can go to separate PR)
ba42df4
Added new "Generalized Event" concept (
GEventProtocol
) and refactoredSignal
.(Other types are currently commented-out and not supported yet)
Before moving onto refactoring other types, I would like to hear what are your thoughts on this!